how to add DataTable and Cell Text both

Hi Guys,

I am Asif. We have a client for whom we are working for this Asp.net web form project. We have selcted SyncFusion SDK for excel formatting import/export feature. We are facing a problem while with the SDK.


If we add a simple Cell text using the following line, it is working good.

sheet.Range["B2"].Text = "Group Code ";


If we add a table with the above line right below of B2, the table does added but B2 cell becomes empty. Can you please let us know what we are making a mistake? Here is the code.


IApplication application = excelEngine.Excel;

application.DefaultVersion = ExcelVersion.Xlsx;

IWorkbook workbook = application.Workbooks.Create(1);

IWorksheet sheet = workbook.Worksheets[0];

DataTable dataTable = setData();

sheet.ImportDataTable(dataTable, 4, 2, true, true);

sheet.Range["B2"].Text = "Group Code "; // become empty with data table

sheet.Range["C2"].Text = EventGroupName; // become empty with data table

sheet.UsedRange.AutofitColumns();

workbook.SaveAs(excelStream);

excelStream.Dispose();

Your guidance will be highly appreciated.


Thank you.

Asif.


1 Reply

RS Ramya Sivakumar Syncfusion Team April 28, 2022 11:58 AM UTC

Hi Asif,


Greetings from Syncfusion.


ImportDataTable overload method which has the ImportOnSave argument allows you to import data with less memory consumption along with improved method performance by serializing the data directly on the save method. This option is preferred for larger data that need to be imported in a short time. ImportOnSave option has the following limitations, so we can’t add the cell values in the file.


Limitations

  • Cannot modify data dynamically
  • Styles cannot be applied
  • Table style cannot be applied
  • Existing sheet data will be lost


To avoid this issue kindly use the following code snippet and let us know if it helps.


Code Snippet:

sheet1.ImportDataTable(dataTable, 4, 2, false, true);


Kindly refer to the following link to know more about the import data table method

https://help.syncfusion.com/file-formats/xlsio/improving-performance#importing-datatable

https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datatable


Regards,

Ramya.


Loader.
Up arrow icon