I am using c# and Interop library and winform. I have a problem with the pdf exported using this code to create pdf, it is working:
Workbook wkb = GetApp().Workbooks.Open(excelLocation);
wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, outputLocation);
wkb.Close();
GetApp().Quit();
It is working but I have problems in the design. The page in pdf at 100% of size (normnal size) is:
Too small, I would like to see the table biggest.
when you open in excel size isnormal. why not in PDF exported file? Do I need extra configuration in ExportAsFixedFormat?
How can I do it?
Does ClosedXML have any function that can be used to save an excel file as PDF?
Currently i am using ClosedXML to create and populate the excel file and then using Interop to save as PDF.
But since Interop depends on the MS Office installed on the syatem the formatting changes on every version of MS Office. And since ClosedXML doesnt require having MS office installed it would be nice to be able to export or save as PDF directly from it without using Interops.
Does ClosedXML have any function that can be used to save an excel file as PDF?
No.
Instead you can use the free version of GemBox.Spreadsheet.
Also look at the top 10 libraries which allows us to manipulate excel.
However GemBox was the only free and featured one that I found with the purpose of creating an invoice report for a website, by converting excel to pdf.
you can use the ClosedXML.Excel and iTextSharp to convert Excel to PDF file.
Here a link with example:
Convert Excel file to Pdf in ASP.Net
In my application I already have functionality to export into 2003 format. Where I am constructing a string out of the template and write using System.IO.File.WriteAllText.
But it does not work with excel 2007/2010, that's why I wanted to convert it to Openxml in order to support 2007 and 2010.
I have string ready with creation of cells and rows from template.
I want advice on how to achieve or any body has reference link.
Please let me know.
Regards
WriteAllText class will save you a text file. You are saving an html(text) based file with xls extension. This is not a real xls file (that is actually a binary file), but MS Excel recognize and interpret the html format.
An xlsx file is a binary file. You can use OpenXML Office library ( Excel.XlFileFormat.xlOpenXMLWorkbook ) or another .NET Excel library like EasyXLS. Check this sample of code for more details.
Simple question. Does anyone know an easy way to convert SpreadsheetML (Excel 2003 XML) to the Open Document XML used for Excel 2007 (xlsx) files?
I've got a library that unfortunately doesn't read the XML format, so I need to try and find a way to read the data, that doesn't involve another library.
Any suggestions appreciated.
If you've got deep pockets Aspose.Cells can read/write both formats and should provide for really easy conversion without automation.
http://www.aspose.com/categories/.net-components/aspose.cells-for-.net/default.aspx
Aspose.Cells for .NET
Aspose.Cells for .NET is an award-winning Spreadsheet component that allows .NET developers to embed the ability to read, write and manipulate Excel spreadsheets into their own applications without needing to rely on Microsoft Excel.
Aspose.Cells for .NET is a mature, scalable and feature rich component that offers many functions that are way beyond the simple data exporting capabilities of other vendors. With Aspose.Cells for .NET developers can export data, format spreadsheets to the most granular level, import images, import charts, create charts, apply and calculate complex formulas, stream Excel data, save in various formats and much more - all this without the need to use Microsoft Excel or Microsoft Office Automation.
Pricing starts at $899 per developer for enterprise (internal) development and goes up from there very steeply.
The file format has indeed changed significantly from SpreadsheetML to Office Open XML.
And, since now spreadsheet files are broken into multiple XML files (which are all then zipped), there's no real hope of an easy XLST solution.
The most straightforward course of action, unfortunately, is to automate Excel using a macro to open each SpreadsheetML files and do a "Save As" to the newer format. This can be done in Office 2003 with the Office 2007 file format plug-in. Perhaps this can be relegated to a batch process so the server is not directly involved?
If the data in the spreadsheets are trivial and follow a consistent format, you can write your own parser to import directly from the SpreadsheetML files.
An easy way would be to use Excel's COM Library (Excel 2007), but I think that's not the answer you are looking for.
What's your library capable of? You could use the Open XML SDK 2.0 to write the spreadsheet document based on the output of your library.
Best Regards
Try using JODConverter. JODConverter allows conversion of SpreadsheetML using the OpenOffice.org or Libreoffice engine.
IIRC the Office 2003 format works like OpenDocument format: It's a ZIP file with XML files inside, so (if you have enough time/courage) you can open it, find the XML file that contains the data and finally deal with XML.
I know, this answer is for brave developers ;)
Regards.
check this code static void XlsToXlsx
static void XlsToXlsx (string sourceFile, string destinationFile)
{
Type officeType = Type.GetTypeFromProgID("Excel.Application");
Excel.Application app = new Excel.Application();
app.DisplayAlerts = false;
// Open Excel Workbook for conversion.
Excel.Workbook excelWorkbook = app.Workbooks.Open(sourceFile);
// Save file as CSV file.
//excelWorkbook.SaveAs(destinationFile, Excel.XlFileFormat.xlCSV);
excelWorkbook.SaveAs(destinationFile, Excel.XlFileFormat.xlOpenXMLWorkbook);
// Close the Workbook.
excelWorkbook.Close();
// Quit Excel Application.
app.Quit();
}
Edit:
I have a user control with embedded excel sheet and gridviews ( WinForm). I have a form which has that user control. I have a print button on top and I want to convert the whole form into printable format. Any suggestion on how to move ahead?
Printing an Excel document can be done using the Workbook.ExportAsFixedFormat method:
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF
FileName:=“sales.pdf”
Quality:=xlQualityStandard
DisplayFileAfterPublish:=True
This method should be preferred over using SaveAs because it also allows specifying all PDF / XPS options.
Note: This method has been added to the Excel object model with Excel 2007 and requires the Save as PDF or XPS Add-in for 2007 Microsoft Office programs to be installed.
See this related question: What is the FileType number for PDF in Excel 2007 that is needed to save a file as PDF through the API?
For versions earlier than 2007 you can embed/install a PDF printer and use the PrintOut method, specifying ActivePrinter as required.