SajjadZare
SajjadZare

Reputation: 2378

Create Excel file with ExcelLibrary

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.

Upvotes: 0

Views: 1788

Answers (2)

emrah kasal
emrah kasal

Reputation: 21

Give a name to your datatable. That will create the sheet name dtTable.TableName = "Sheet1"

Upvotes: 0

Vandal
Vandal

Reputation: 911

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!

Upvotes: 1

Related Questions