I want to export gridview to excel file and import excel to gridvie.
when i open this exported file I am getting the following warning message.
The file format and extension of 'Export.xls' don't match the file could not be correpted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway ?
I searched for this warning message but i am not getting correct result.
In Excel file old version(2003) format it is working properly but when I open this file in latest version (after 2007) I am getting warning message and my operations also failed.
so pleas tell me how to export and import gridview in latest version excel file .

Vithal WadjeRank #19 · 47.2K reputationPosted Oct 20, 2012, 4:48 AM EDT
Lacy Michelle148 reputationPosted Oct 21, 2012, 10:58 PM EDT
export gridview to excel, look at below code:
private void btnRun_Click(object sender, System.EventArgs e)
{
Workbook workbook = new Workbook();
//Initialize worksheet
Worksheet sheet = workbook.Worksheets[0]; sheet.InsertDataTable((DataTable)this.dataGrid1.DataSource,true,2,1,-1,-1);
workbook.SaveToFile("sample.xls");
ExcelDocViewer( workbook.FileName );
}
excel to datatable:
namespace Export { class Program { static void Main(string[] args) { //Create a workbook Workbook workbook = new Workbook(); //Load the file workbook.LoadFromFile("DataTableSample.xls"); //Initailize worksheet Worksheet sheet = workbook.Worksheets[0]; //Export datatable DataTable dataTable = sheet.ExportDataTable(); } } }raja ramesh46 reputationPosted Oct 22, 2012, 1:45 AM EDT
Thank you for reply, I unable to get data from bytes. In you case you have written one of the line
com.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
But how can i use this li, In my case I have Customer table and it has customerid(pk), customerName, address,... so how can i achieve data from bytes.
Thanks in advance,
raja
Vithal WadjeRank #19 · 47.2K reputationPosted Oct 23, 2012, 2:11 AM EDT