using IronXL;// Load the Excel spreadsheetWorkBook workbook = WorkBook.Load("sample.xlsx");// Convert and save as CSVworkbook.SaveAsCsv("sample.csv");// Convert and save as JSONworkbook.SaveAsJson("sample.json");// Convert and save as XMLworkbook.SaveAsXml("sample.xml");// Convert and export to HTMLworkbook.ExportToHtml("sample.html");// The files will be saved in the project's directory with the specified formats
using IronXL;
// Load the Excel spreadsheet
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Convert and save as CSV
workbook.SaveAsCsv("sample.csv");
// Convert and save as JSON
workbook.SaveAsJson("sample.json");
// Convert and save as XML
workbook.SaveAsXml("sample.xml");
// Convert and export to HTML
workbook.ExportToHtml("sample.html");
// The files will be saved in the project's directory with the specified formats
ImportsIronXL' Load the Excel spreadsheetDim workbook AsWorkBook = WorkBook.Load("sample.xlsx")' Convert and save as CSVworkbook.SaveAsCsv("sample.csv")' Convert and save as JSONworkbook.SaveAsJson("sample.json")' Convert and save as XMLworkbook.SaveAsXml("sample.xml")' Convert and export to HTMLworkbook.ExportToHtml("sample.html")' The files will be saved in the project's directory with the specified formats
Imports IronXL
' Load the Excel spreadsheet
Dim workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Convert and save as CSV
workbook.SaveAsCsv("sample.csv")
' Convert and save as JSON
workbook.SaveAsJson("sample.json")
' Convert and save as XML
workbook.SaveAsXml("sample.xml")
' Convert and export to HTML
workbook.ExportToHtml("sample.html")
' The files will be saved in the project's directory with the specified formats
using IronXL;// Load the Excel spreadsheetWorkBook workbook = WorkBook.Load("advanced_sample.xlsx");// Convert and save to various formatsworkbook.SaveAs("advanced_sample.xlsm");workbook.SaveAsCsv("advanced_sample.csv");workbook.SaveAsJson("advanced_sample.json");workbook.SaveAsXml("advanced_sample.xml");workbook.ExportToHtml("advanced_sample.html");// You can also convert to binary or byte array for advanced usesbyte[] excelAsByteArray = workbook.ToBinary();
using IronXL;
// Load the Excel spreadsheet
WorkBook workbook = WorkBook.Load("advanced_sample.xlsx");
// Convert and save to various formats
workbook.SaveAs("advanced_sample.xlsm");
workbook.SaveAsCsv("advanced_sample.csv");
workbook.SaveAsJson("advanced_sample.json");
workbook.SaveAsXml("advanced_sample.xml");
workbook.ExportToHtml("advanced_sample.html");
// You can also convert to binary or byte array for advanced uses
byte[] excelAsByteArray = workbook.ToBinary();
ImportsIronXL' Load the Excel spreadsheetDim workbook AsWorkBook = WorkBook.Load("advanced_sample.xlsx")' Convert and save to various formatsworkbook.SaveAs("advanced_sample.xlsm")workbook.SaveAsCsv("advanced_sample.csv")workbook.SaveAsJson("advanced_sample.json")workbook.SaveAsXml("advanced_sample.xml")workbook.ExportToHtml("advanced_sample.html")' You can also convert to binary or byte array for advanced usesDim excelAsByteArray AsByte() = workbook.ToBinary()
Imports IronXL
' Load the Excel spreadsheet
Dim workbook As WorkBook = WorkBook.Load("advanced_sample.xlsx")
' Convert and save to various formats
workbook.SaveAs("advanced_sample.xlsm")
workbook.SaveAsCsv("advanced_sample.csv")
workbook.SaveAsJson("advanced_sample.json")
workbook.SaveAsXml("advanced_sample.xml")
workbook.ExportToHtml("advanced_sample.html")
' You can also convert to binary or byte array for advanced uses
Dim excelAsByteArray As Byte() = workbook.ToBinary()
try{ WorkBook workbook = WorkBook.Load("input.xlsx"); // Check if the file has data before converting if (workbook.WorkSheets.Count > 0 && workbook.DefaultWorkSheet.RowCount > 0) { workbook.SaveAsCsv("output.csv");Console.WriteLine("Conversion successful!"); } else {Console.WriteLine("No data found in the spreadsheet."); }}catch (Exception ex){Console.WriteLine($"Conversion failed: {ex.Message}");}
try
{
WorkBook workbook = WorkBook.Load("input.xlsx");
// Check if the file has data before converting
if (workbook.WorkSheets.Count > 0 && workbook.DefaultWorkSheet.RowCount > 0)
{
workbook.SaveAsCsv("output.csv");
Console.WriteLine("Conversion successful!");
}
else
{
Console.WriteLine("No data found in the spreadsheet.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Conversion failed: {ex.Message}");
}
ImportsSystemTry Dim workbook AsWorkBook = WorkBook.Load("input.xlsx") ' Check if the file has data before converting If workbook.WorkSheets.Count > 0AndAlso workbook.DefaultWorkSheet.RowCount > 0 Then workbook.SaveAsCsv("output.csv")Console.WriteLine("Conversion successful!") ElseConsole.WriteLine("No data found in the spreadsheet.") End IfCatch ex AsExceptionConsole.WriteLine($"Conversion failed: {ex.Message}")EndTry
Imports System
Try
Dim workbook As WorkBook = WorkBook.Load("input.xlsx")
' Check if the file has data before converting
If workbook.WorkSheets.Count > 0 AndAlso workbook.DefaultWorkSheet.RowCount > 0 Then
workbook.SaveAsCsv("output.csv")
Console.WriteLine("Conversion successful!")
Else
Console.WriteLine("No data found in the spreadsheet.")
End If
Catch ex As Exception
Console.WriteLine($"Conversion failed: {ex.Message}")
End Try
What are the best practices for converting files using IronXL?
Best practices for file conversion with IronXL include preserving data integrity, using appropriate error handling, choosing the suitable output format for your needs, and paying attention to character encoding.
When should I use JSON as the export format with IronXL?
JSON is an ideal export format when working with web services, REST APIs, and modern JavaScript applications due to its lightweight structure and ease of use in data interchange and integration.
Is it possible to convert Excel data into formats suitable for database operations with IronXL?
Yes, IronXL can export Excel data to formats suitable for database operations, such as `DataSet` and `DataTable`, allowing easy integration with SQL databases or other data processing systems.
What are the customization options available for converting spreadsheets using IronXL?
IronXL offers various customization options for converting spreadsheets, including specific export methods like SaveAsCsv or SaveAsJson for different formats, and the ability to convert Excel data into binary or byte arrays for advanced uses.