I use ExcelLibrary to create an excel from a DataSet
. I use the below code to create a DataSet
and create Excel.
DataTable dtTable = new DataTable();
dtTable.Columns.Add(new DataColumn("name", typeof(string)));
DataRow dr = dtTable.NewRow();
dr[0] = "test";
dtTable.Rows.Add(dr);
DataSet ds = new DataSet();
ds.Tables.Add(dtTable);
ExcelLibrary.DataSetHelper.CreateWorkbook(textBox1.Text, ds);
But when the excel is created, there are no rows in Excel.
Try this.
DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Columns.Add("Code");
DataRow row1 = dt.NewRow(); row1["Name"] = "Abundantcode"; row1["Code"] = "1-1-1"; dt.Rows.Add(row1);
Source .
Hope it helps!
Give a name to your datatable. That will create the sheet name dtTable.TableName = "Sheet1"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.