我想將數據導出到Excel模板。工作簿中有多個選項卡。我想要導出到的工作表標籤被稱爲「可行性」。問題是:如何導出到此特定的工作表名稱?導出到特定的Excel工作表名稱
using Excel = Microsoft.Office.Interop.Excel;
//excel output variables
private string excelFileName = SqlDB.GetFolderTemplates() + SqlDB.GetFileEngOrd();
private static Excel.Application xlsApp;
private static Excel.Workbooks workbooks;
private static Excel.Workbook workbook;
private Excel.Worksheet worksheet;
private void btnFeasibility_Click(object sender, EventArgs e)
{
xlsApp = new Excel.ApplicationClass();
if (xlsApp == null)
{
MessageBox.Show(Constants.EXCEL_INSTALL);
return;
}
try
{
xlsApp.Visible = true;
workbooks = xlsApp.Workbooks;
workbook = xlsApp.Workbooks.Open(excelFileName);
//PROBLEM IS HERE -- HOW CAN I GO TO THE WORKSHEET NAMED "FEASIBILITY"
worksheet = (Excel.Worksheet)workbook.Sheets[1];
worksheet.Select();
worksheet.Cells[3, 4] = newEngOrd.CustName;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
//release excel
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
worksheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
workbook = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp);
xlsApp = null;
GC.GetTotalMemory(false);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.GetTotalMemory(true);
MessageBox.Show("Export Complete");
}
}
我編輯了您的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –
好的 - 學到了一些新的感謝。 – maverick07281975