I am trying to display a excel document in a windows form using c#. My plan is to convert and xlsx document into either html or pdf and then display it either through Aspose's editor control (as html) or through the webbrowsercontrol (as pdf). I want to read a excel file into a filestream convert it to html and then display the html through the editor. Can anyone guide me through how to do this.
Well, we have recently introduced the feature in the new version of GridDesktop i.e…, Importing / Exporting Xlsx files: File Format APIs for .NET Core, Java, Python, C++, Android | products.aspose.com I think you need to utilize two components i.e…, Aspose.Grid.Desktop and Aspose.Cells for .NET for your task. You may utilize Aspose.Grid.Desktop to open/view the xlsx file to the control and then use Aspose.Cells for .NET to convert the file to html and pdf formats as Aspose.Cells for .NET supports these features.
To open the file into GridDesktop, see the code below:
//Opening MS Excel 2007 Xlsx file specifying its path gridDesktop1.ImportExcelFile(“D:\test\book1.xlsx”, FileFormatType.Excel2007Xlsx);
To convert the xlsx file to pdf, please check the doc topic and codes for your reference:
//Instantiate the Workbook object
Workbook workbook = new Workbook();
//Open an excel file
workbook.Open("f:\\test\\Book1.xlsx");
//Save the document in Pdf format
workbook.Save("f:\\test\\outBook1.pdf", FileFormatType.Pdf);
//Save the document to html format
workbook.Save("f:\\test\\outBook1.html", FileFormatType.Html);
Getting file into stream
//Get an excel file path in a variable.
string path = @"f:\test\Book1.xlsx";
FileStream fs = File.OpenRead(path);
Aspose.Cells.Workbook workbook = new Workbook();
workbook.Open(stream, FileFormatType.Excel2007Xlsx);
//Save the document in Pdf format
workbook.Save("f:\\test\\outBook1.pdf", FileFormatType.Pdf);
//Save the document to html format
workbook.Save("f:\\test\\outBook1.html", FileFormatType.Html);
The gridDesktop1.ImportExcelFile claims that I have invalid arguments when doing this. The paramters include (string filePath), (Stream stream), or (string filePath, bool runFormulas). It does not accept a fileFormatType. And When I save a excel file as a html file into the stream and try to display the stream into the Aspose.editor control, I get the source code but not a view of the file.