I am having a linux machine and want system drawing to convert a excel table to image for Free.
Here is my code
using GrapeCity.Documents.Excel;
using System;
using System.Drawing;
using System.IO;
class Program
{
static void Main()
{
//Create a new workbook
var workbook = new GrapeCity.Documents.Excel.Workbook();
Console.WriteLine("Working...");
FileStream fileStream = new FileStream("Test121.xlsx", FileMode.Open);
//Open a xlsx file
workbook.Open(fileStream);
IWorksheet worksheet = workbook.Worksheets[0];
//Export the worksheet to image
worksheet.ToImage("Test121.png");
Console.WriteLine("Done!!");
}
}
but this gives a warning at top of image that it is unlicensed
I also could not use Spire.XLS as my excel file could have more than 200 rows.
btw i am using C#.Net on my ubuntu 20.04 LTS
Related
I am using Syncfusion library to generate an excel report. I referred syncfusion to generate the report using template makers. The data is correctly exported in excel file but it is exporting NULL instead of blank string for some of nullable number columns. How can I write blank instead of NULL in excel for nullable fields.
Template file:
Output:
This is the code I am using.
using Syncfusion.XlsIO;
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2010;
IWorkbook workbook = application.Workbooks.Open(_templateFilePath);
IWorksheet worksheet = workbook.Worksheets[0];
ITemplateMarkersProcessor marker = workbook.CreateTemplateMarkersProcessor();
var data = _database.GetData();
marker.AddVariable("DATA", data);
marker.ApplyMarkers();
workbook.SaveAs(_stReportFilePath);
workbook.Close();
excelEngine.Dispose();
}
i'am trying to get an xls file from an ZipArchive but cant get it with EPPLUS
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry != null)
{
string filepath = entry.FullName;
FileInfo fileInfo = new FileInfo(filepath);
//here i got the excel package with the xls file inside the excelPackage
using (ExcelPackage excelPackage = new ExcelPackage(fileInfo))
{
//but here impossible de get the worksheet or workbook inside or anything else
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault();
int totalColomn = worksheet.Dimension.End.Column;
int nbrsheet = excelPackage.Workbook.Worksheets.Count();
}
}
}
the ExcelPackage i get in debug
i see the xls file on debug inside the excelpackage but just when i try to get worksheet it exit without exception code....
same here when trying with entryStream
using (var entryStream = entry.Open())
{
//Cant even get the excelpackage, it crash here without exception
using (ExcelPackage excelPackage = new ExcelPackage(entryStream))
{
ExcelWorksheet worksheetest = excelPackage.Workbook.Worksheets.FirstOrDefault();
}
}
the stream here seem also strange ...
entryStream Debug
Working with .NET CORE Blazor ServerSide, ePPLUS 4.5
Thanks for helping
entry.FullName refers to the full path to the file inside the zip archive, while FileInfo describes a file in the filesystem of the OS, which is a completely different thing. You haven't extracted anything to the OS filesystem yet, so the FileInfo won't refer to a file that actually exists.
Try the ExcelPackage constructor that takes a Stream, which you can get directly from a ZipArchiveEntry:
using (var entryStream = entry.Open())
{
using (ExcelPackage excelPackage = new ExcelPackage(entryStream))
{
// ...
}
}
I find the problem.
it was that i tried to get an xls file and the epplus library dont work with it...
you have to be careful, EPplus dont work with xls file
So , your solution Jeff is working, it was my fault, didn't specified the extension of my excel file... sorry
-> EPlus with an .xlsx OK, not .xls
My bad.
Thanks anyway :-)
I am trying to access excel modules with C# and I am having trouble after saving the excel file.
There are duplicate Thisworkbook and Sheets appearing as the picture below.
This only happens when the excel file has Modules while everything will be fine if the excel has only sheets in the project.
Here is the code which is nothing but only opening and saving the same file.
I am using WIN10/ VS2013 /EXCEL 2010.
Does anyone know why will this happen?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Vbe.Interop;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string filepath = #"C:\test.xls";
Excel._Application app = new Excel.Application();
Excel._Workbook workbook = app.Workbooks.Open(filepath);
workbook.SaveAs(filepath);
workbook.Close(true);
app.Quit();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.Data.OleDb;
namespace EXCEL_SMS
{
class Program
{
static void Main(string[] args)
{
string path = "C:\\Projects\\ExcelSingleValue\\Test.xlsx ";
Application excel = new Application();
Workbook wb = excel.Workbooks.Open(path);
Worksheet excelSheet = wb.Activesheet;
// Read the first cell
string test = excelSheet.Cells[1, 1].Value.ToString();
// string sValue = (range.Cells[2, 4] as Microsoft.Office.Interop.Excel.Range).Value2.ToString();
wb.Close();
}
}
}
I am getting error at activesheet, I want read cell value from Excel while it's open. Can anyone tell how I can achieve it? I'm using Visual Studio 2012.
there is a mistake in "ActiveSheet" please correct it will work fine, in your code it is "Activesheet" ('s' is a small need to be Capital 'S')
Worksheet excelSheet = wb.ActiveSheet; //wb.Activesheet;
Please see the result I am getting with the same program as below, I am able to get the first Cell from test.xlsx
I have several DataTable objects and I want to write them to one excel file but various sheets.
I'm using bytescout.spreadsheet to work with excel files.
How can I write multiple table sheets to excel file using this tool and C#?
Read the manual: http://bytescout.com/products/developer/spreadsheetsdk/bytescoutxls_working_with_worksheets_in_xls_document.html
using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.Spreadsheet;
namespace Worksheets
{
internal class Program
{
private static void Main(string[] args)
{
// Create new Spreadsheet
Spreadsheet document = new Spreadsheet();
// Add worksheets
Worksheet worksheet1 = document.Workbook.Worksheets.Add("Demo worksheet 1");
Worksheet worksheet2 = document.Workbook.Worksheets.Add("Demo worksheet 2");
// Get worksheet by name
Worksheet worksheetByName = document.Workbook.Worksheets.ByName("Demo worksheet 2");
// Set cell values
worksheet1.Cell(0, 0).Value = "This is Demo worksheet 1";
worksheetByName.Cell(0, 0).Value = "This is Demo worksheet 2";
// Save document
document.SaveAs("Worksheets.xls");
}
}