How to set date format for entire sheet using XlsIO?
Setting a number format for an entire sheet at once is not possible with XlsIO. However, this approach also affects performance and impacts memory usage.
To apply a number format to all the cells, we recommend utilizing the UsedRange property of IRange. This will apply the same format to all the used range cells in a worksheet. The following code snippets illustrate the same for your reference.
C#
IWorkbook workbook = application.Workbooks.Open(@"../../Data/syncfusion.xlsx", ExcelOpenType.Automatic); IWorkbook workbook1 = application.Workbooks.Open(@"../../Data/sample.xlsx", ExcelOpenType.Automatic); IWorksheet sheet = workbook.Worksheets[0]; IWorksheet sheet1 = workbook1.Worksheets[0]; DataTable dataTable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames); sheet1.ImportDataTable(dataTable, false, 1, 1); sheet.UsedRange.NumberFormat = "mm/dd/yyyy";
VB
Dim workbook As IWorkbook = application.Workbooks.Open("../../Data/syncfusion.xlsx", ExcelOpenType.Automatic) Dim workbook1 As IWorkbook = application.Workbooks.Open("../../Data/sample.xlsx", ExcelOpenType.Automatic) 'IWorkbook workbook = application.Workbooks.Create(1); Dim sheet As IWorksheet = workbook.Worksheets(0) Dim sheet1 As IWorksheet = workbook1.Worksheets(0) Dim dataTable As DataTable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames) sheet1.ImportDataTable(dataTable, False, 1, 1) sheet.UsedRange.NumberFormat = "mm/dd/yyyy"
The sample illustrating this behavior is available here.
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 set date format for entire sheet using XlsIO.
You can refer to our XlsIO’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!