怎么没人那?帮帮忙!
以下代码是我将一个dataset的数据成功导入到Excel的sheet1中,我想再将另一个dataset的数据导入该Excel的sheet2中,不知该如何修改下面的代码?求助大侠们,万分急!
Excel.Application excel= new Excel.Application() ;
excel.Application.Workbooks.Add(true) ;
excel.Visible = true ;
excel.Cells[1,1] = "参数配置基本表" ;
int rowCount;
rowCount=this.dataSet_Config1.config.Rows.Count;//要导入Excel的dataset
excel.Cells[3,1] = "系统编号" ;
excel.Cells[3,2] = "分系统编号";
excel.Cells[3,3] = "站ID" ;
excel.Cells[3,4] = "IO模块ID";
excel.Cells[3,5] = "IO模块类型";
///添加数据
for(int i=0;i<rowCount;i++) ///每一行
{
excel.Cells[i+4,1] = this.dataSet_Config1.config.Rows[i]["系统编号"];
excel.Cells[i+4,2] = this.dataSet_Config1.config.Rows[i]["分系统编号"];
excel.Cells[i+4,3] = this.dataSet_Config1.config.Rows[i]["站ID"];
excel.Cells[i+4,4] = this.dataSet_Config1.config.Rows[i]["IO模块ID"];
excel.Cells[i+4,5] = this.dataSet_Config1.config.Rows[i]["IO模块类型"];
}
//格式的变化
Excel._Workbook mybook;
Excel._Worksheet mySheet;
Excel.Range oRng;
mybook=excel.ActiveWorkbook;
mySheet=(Excel._Worksheet)mybook.ActiveSheet;
oRng = mySheet.get_Range("A1","B1");
oRng.Merge(0);
oRng.Font.Bold=true;
oRng.Font.Size=16;
rowCount=rowCount+3;
string endCell=rowCount.ToString();
endCell="E"+endCell;
oRng = mySheet.get_Range("A3",endCell);
oRng.Borders.get_Item( Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlContinuous;
oRng.Borders.get_Item( Excel.XlBordersIndex.xlInsideVertical).LineStyle
= Excel.XlLineStyle.xlContinuous;
oRng.Borders.get_Item( Excel.XlBordersIndex.xlEdgeTop).LineStyle
= Excel.XlLineStyle.xlContinuous;
oRng.Borders.get_Item( Excel.XlBordersIndex.xlEdgeLeft).LineStyle
= Excel.XlLineStyle.xlContinuous;
oRng.Borders.get_Item( Excel.XlBordersIndex.xlEdgeRight).LineStyle
= Excel.XlLineStyle.xlContinuous;
oRng.Borders.get_Item( Excel.XlBordersIndex.xlEdgeBottom).LineStyle
= Excel.XlLineStyle.xlContinuous;
oRng.EntireColumn.AutoFit();