Friday 1 March 2019

Xls,XLSx console application using Datatable


Package Manage Console - Install-Package ExpertXls.ExcelLibrary -Version 5.0.0


Code :
--------

private static void GenerateTxtFileFromDataTable(DataTable sampleDataTable,string delimiter)
        {
            var _expertxlsLK = ConfigurationManager.AppSettings["ExpertxlsLK"];
            //hK+1pLe2pLykt6q0pLe1qrW2qr29vb0=
            // Create the workbook in which the data from the DataTable will be loaded
            ExcelWorkbookFormat workbookFormat = ExcelWorkbookFormat.Xlsx_2007;

            // create the workbook in the desired format with a single worksheet
            ExcelWorkbook workbook = new ExcelWorkbook(workbookFormat);
            workbook.EnableFormulaCalculations();

            workbook.LicenseKey = _expertxlsLK;

            // get the first worksheet in the workbook
            ExcelWorksheet worksheet = workbook.Worksheets[0];

            // set the default worksheet name
            worksheet.Name = "ClaimInformation";

            // load data from DataTable into the worksheet
            worksheet.LoadDataTable(sampleDataTable, 1, 1, true);
            worksheet.Workbook.EnableFormulaCalculations();
            workbook.Save(@"M:\Rupesh\test.xlsx");
            workbook.Close();
        }

1 comment:

  1. Prepare for Microsoft MB-200 exam with our preparation material with full confidence. We offer you 100% real Microsoft Dynamics 365 Customer Engagement Core Microsoft MB-200 exam dumps for your better results. Prepare4Test’s MB-200 pdf dumps are verified by Microsoft Gurus.

    ReplyDelete