Articles in this section
Category / Section

How to use ImportOnSave option while importing data using XlsIO?

1 min read

ImportDataTable overload method, which has the ImportOnSave argument, allows importing data with less memory consumption and improved method performance by serializing the data directly in the save method. This option is preferred for larger data that needs to be imported in a short time.

The following complete code snippet explains this:

// Create an instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
 
    FileStream inputStream = new FileStream("NorthwindDataTemplate.xls", FileMode.Open);
    IWorkbook existing_workbook = application.Workbooks.Open(inputStream);
    IWorksheet existing_worksheet = existing_workbook.Worksheets[0];
 
    DataTable table = existing_worksheet.ExportDataTable(1, 1, existing_worksheet.UsedRange.LastRow, existing_worksheet.UsedRange.LastColumn, ExcelExportDataTableOptions.DetectColumnTypes);
 
    IWorkbook new_workbook = application.Workbooks.Create(1);
    new_workbook.Worksheets[0].ImportDataTable(table, 1, 1, true, true);
 
    new_workbook.Version = ExcelVersion.Excel2013;
 
    // Save the document as a stream and retrun the stream.
    using (MemoryStream stream = new MemoryStream())
    {
        //Save the created Excel document to MemoryStream
        new_workbook.SaveAs(stream);
         return stream;
    }
}

 

A complete working sample can be downloaded from ImportOnSave.zip.

See Also:

Working with Data using XlsIO


Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through formulas, adding charts in worksheets or workbooks, organizing and analyzing data through tables and pivot tables, appending multiple records to a worksheet using template markers, and most importantly, PDF and image conversions, etc., with code examples.

Refer here to explore the rich set of Syncfusion Essential XlsIO features.

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to this link to learn about generating and registering the Syncfusion license key in your application to use the components without a trial message.

 

Conclusion

I hope you enjoyed learning about how to use ImportOnSave option while importing data using XlsIO.

 

You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents. 

If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion components.

If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied