2013-10-29 85 views
0

我在尋找如何將數據網格(不DataGridView中)導出到Excel中我的工作VS 2003的winform。我在找上了網,但是沒有結果,我找到的解決方案是隻是(datagridview的VS 2010 ...(ASP ..) 請幫我 THANK YOU出口的DataGrid到Excel C#的winform

這是我到目前爲止有:

lblMessage.Text = ""; 
// Export all the details 
try 
{ 
    // Get the datatable to export 
    DataTable dtEmployee = dsEmployee.Tables["Employee"].Copy(); 
    // Export all the details to Excel 
    RKLib.ExportData.Export objExport = new RKLib.ExportData.Export("Win"); 
    objExport.ExportDetails(dtEmployee, Export.ExportFormat.Excel, "C:\\EmployeesInfo.xls"); 
    lblMessage.Text = "Successfully exported to C:\\EmployeesInfo.xls"; 
} 
catch(Exception Ex) 
{ 
    lblMessage.Text = Ex.Message; 
} 
+0

你想要做的代碼? –

+1

你有沒有試過這個http://stackoverflow.com/questions/373925/c-sharp-winforms-app-export-dataset-to-excel?rq=1 –

+0

是的,我想通過代碼:) – Meryem

回答

0

閱讀網(僞代碼):

// Here Interop to Excel Application, save empty workbook (xls file) 
// Here connect to the create workbook using ACE 
for (int i = 0; i < grid.rows.count; i++) 
{ 
    for (int j = 0; j < grid.columns.count; j++) 
    { 
     // here use one of the methods described in this link to write data 
     // http://support.microsoft.com/kb/306023 
     // -----> grid.Item(i, j) = excel cell <-------- 
    } 
} 

看到這個:

Writing to excel using OleDb

同樣在此:

準在網格中Excel例如一個小區到小區A1,D7等

http://support.microsoft.com/kb/302094

+0

此代碼不適用於VS 2003中的datagrid:s – Meryem

+0

這是不正確的。網格有財產'項目 - http://msdn.microsoft.com/en-us/library/system.windows.forms.datagrid_properties%28v=vs.110%29.aspx 所以這段代碼應該這樣做 –

+0

是的但我不能寫這個:datagrid1.rows或datagrid1.Columns – Meryem