Hi,
I would like to export some images and some datatables to an excel sheet. Similarly I have to export to many other excel sheets in the same excel workbook using C#.
Is there any easier way of doing this?
Thanks in advance,
Thana
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Alex HeigPosted Feb 27, 2013, 4:13 AM
ExcelWorkbook Wbook = ExcelWorkbook.ReadXLS(@"c:\test.xls");
ExcelWorksheet Wsheet=Wbook.Worksheets.Add("Wsheet1");
// to export datatable to excel worksheet
Wsheet.ReadFromDataTable(dt);
// to insert image into worksheet
Wsheet.Pictures.Add(@"c:\pic.jpg");
Wsheet.Pictures[0].SetPosition(0, 0);
//save result file
Wbook.WriteXLS(@"c:\test.xls");
George ericPosted Apr 9, 2012, 2:09 AM
The codes are below:
using(OleDbConnection oleDbConnection = new OleDbConnection())
{
oleDbConnection.ConnectionString = this.textBox1.Text;
OleDbCommand oleDbCommand = new OleDbCommand();
oleDbCommand.CommandText = this.textBox2.Text;
oleDbCommand.Connection = oleDbConnection;
using(OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
{
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
}
SenthilkumarPosted Apr 4, 2012, 2:41 AM
Please refer these urls:
http://www.codeproject.com/Articles/164582/8-Solutions-to-Export-Data-to-Excel-for-ASP-NET
http://www.dotnetgallery.com/lab/resource44-Export-to-excel-from-DataTable-using-CNET.aspx