Last post Feb 24, 2016 03:28 AM by Fei Han - MSFT
Feb 23, 2016 02:50 AM|EDVIN GEORGE|LINK
I am trying to insert a data set values to a named range, but data inserts to the first row even though the Named range is defined at diffrent location , say A17 to H17.
It was working fine in xls fomat. But it is not working in .XLSX files. Please help
Feb 24, 2016 03:28 AM|Fei Han - MSFT|LINK
Hi EDVIN GEORGE,
data inserts to the first row even though the Named range is defined at diffrent location , say A17 to H17.
Firstly, could you share us your relevant code for exporting data to excel?
Secondly, you could refer to the following sample code.
private void ExportDataSetToExcel(DataSet ds)
//Creae an Excel application instance
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
//Create an Excel workbook instance and open it from the predefined location
Microsoft.Office.Interop.Excel.Workbook excelWorkBook = excelApp.Workbooks.Open(@"d:\info.xlsx");
foreach (DataTable table in ds.Tables)
//Add a new worksheet to workbook with the Datatable name
Microsoft.Office.Interop.Excel.Worksheet excelWorkSheet = excelWorkBook.Sheets.Add();
excelWorkSheet.Name = table.TableName;
for (int i = 1; i < table.Columns.Count + 1; i++)
//start at 17
excelWorkSheet.Cells[17, i] = table.Columns[i - 1].ColumnName;
for (int j = 0; j < table.Rows.Count; j++)
for (int k = 0; k < table.Columns.Count; k++)
excelWorkSheet.Cells[j + 18, k + 1] = table.Rows[j].ItemArray[k].ToString();