Is there a way I can use a DataTable that has html values in most fields and do that following:
- Format the cells with the html in the datatable. example (some cells might be This is bold text
- Auto set the cells data type, example, Data, Time, Currency, Number, or General.
I am not very keen with the Workbook(DataTabele, LoadOptions) method. any assistance would be great.
@rileyja,
Aspose.Cells provides the facility to import data table into workbook having different types of data including html strings, integer and date type. Please give it a try and share the feedback.
// Prepare a DataTable with some HTML formatted values
DataTable dataTable = new DataTable("Products");
dataTable.Columns.Add("Product ID", typeof(Int32));
dataTable.Columns.Add("Product Name", typeof(string));
dataTable.Columns.Add("Units In Stock", typeof(Int32));
dataTable.Columns.Add("ProductDate", typeof(DateTime));
DataRow dr = dataTable.NewRow();
dr[0] = 1;
dr[1] = "<i>Aniseed</i> Syrup";
dr[2] = 15;
dr[3] = DateTime.Now;
dataTable.Rows.Add(dr);
dr = dataTable.NewRow();
dr[0] = 2;
dr[1] = "<b>Boston Crab Meat</b>";
dr[2] = 123;
dr[3] = DateTime.Now;
dataTable.Rows.Add(dr);
// Create import options
ImportTableOptions importOptions = new ImportTableOptions();
importOptions.IsFieldNameShown = true;
importOptions.IsHtmlString = true;
// Create workbook
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells.ImportData(dataTable, 0, 0, importOptions);
worksheet.AutoFitRows();
worksheet.AutoFitColumns();
workbook.Save(@"output.xlsx");