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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Apr 3, 2012, 10:41 PM EDT
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
George ericRank #9,604 · 204 reputationPosted Apr 8, 2012, 10:09 PM EDT
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;
}
}
Alex Heig6 reputationPosted Feb 26, 2013, 11:13 PM EST
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");