Can't open basic xlsx file.

Hi,

I am trying to run your most basic example for XlsIO.  Copied directly from your documentation example.


using (ExcelEngine excelEngine = new ExcelEngine())

            {

               IApplication application = excelEngine.Excel;

               application.DefaultVersion = ExcelVersion.Excel2013;

               IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");

               IWorksheet worksheet = workbook.Worksheets[0];


               //Export worksheet data into Collection Objects

               List<SAData> collectionObjects = worksheet.ExportData<SAData>(2, 1, 10, 3);


               workbook.SaveAs("CollectionObjects.xlsx");

            }


But I am getting an error for :

IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");

Error CS1503 Argument 1: cannot convert from 'string' to 'System.IO.Stream' 

It looks like Workbook.Open() doesn't even take a string argument.  Why does your most basic example not work???

I was trying to open a file on my PC using the full path...



2 Replies

RT Robert Twickler August 28, 2021 02:35 PM UTC

I just added:

FileStream stream = new FileStream(saFile, FileMode.Open);

 IWorkbook workbook = application.Workbooks.Open(stream);


And it works fine. So I am good.  But shouldn't your example show this??



KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team August 30, 2021 04:41 AM UTC

Hi Robert, 

Greetings from Syncfusion. 

We are glad that you have found the solution and issue is resolved at your end.  

The behavior is,  

  • If your application is targeted with .NET Framework versions, then you can directly open the workbook using file path.
  • If your application is targeted with .NET Core versions, the it is recommended to open the workbook as file stream.

This is documented and you can spot the difference in code snippets under C# and ASP.NET Core tabs. 



Kindly let us know if you need any further assistance. 

Regards, 
Keerthi. 


Loader.
Up arrow icon