您的位置:首页 > 其它

从一个excel复制到另外一个excel

2009-10-21 12:02 267 查看
Excel.Range m_objRange = null;
wbs.Open(source_path, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

//進行數據導出的主要代碼斷。
wb = (Excel.Workbook)wbs.get_Item(1);
Excel.Sheets st = wb.Worksheets;
//開始寫入日期
sheetdatetime = (Excel.Worksheet)st.get_Item(1);
for (int i = 1; i <= ds_datetime.Tables[0].Rows.Count; i++)
{
sheetdatetime.Cells[1, i] = ds_datetime.Tables[0].Rows[i - 1][0];
}

////更新數據
//exe_GDS_GenReport_procedure(customer, conn, flag[1]);
//System.Runtime.InteropServices.Marshal.ReleaseComObject(sheetdatetime);

//開始數據的錄入與表的生成

ds_part = get_part_target(conn);
//產生相應的表后同時對連個summary表進行操作。
ww_Summary_sheet = (Excel.Worksheet)st.get_Item(2);
regional_Summary_sheet = (Excel.Worksheet)st.get_Item(3);
int i_region_asl = 4, i_region_esl = 446, i_region_china = 868, i_region_apcc = 1290, i_region_japan = 1712, i_region_ww = 2134;
int i_ww_top = 3;
int base_count=0;
//ds_Rport_data = get_Report_data(conn);
Excel.Workbooks work_base=null;
Excel.Workbook wb_Base=null;
Excel.Worksheets st_Base=null;
Excel.Sheets sht_base = null;
Excel.Range range_Get = null;
for (int i = 0; i < ds_part.Tables[0].Rows.Count; i++)
{

if (i >= Ubound && i < 420)
{
//spilt the Excel
if (i == Ubound)
{
wbs.Open(replace_Goalpath, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);//不同excel用一个workbook打开,另外声明一个exce.application对象那会一起线程异常错误
wb_Base = (Excel.Workbook)wbs.get_Item(2);
sht_base = wb_Base.Worksheets;
sheetCopy = (Excel.Worksheet)sht_base.get_Item(1);
for (int k = 1; k <= ds_datetime.Tables[0].Rows.Count; k++)
{
sheetCopy.Cells[3, k+4] = ds_datetime.Tables[0].Rows[k - 1][0];
}
}
sheetCopy1=null;
sheetCopy = (Excel.Worksheet)sht_base.get_Item(base_count + 1);
sheetCopy.Copy(sheetCopy,Type.Missing);
sheetCopy1 = (Excel.Worksheet)sht_base.get_Item(base_count + 1);
sheetCopy1.Cells[1, 4] = ds_part.Tables[0].Rows[i][0];
sheetCopy1.Cells[3, 4] = ds_part.Tables[0].Rows[i][1];
sheetCopy1.Name = ds_part.Tables[0].Rows[i][0].ToString();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐