使用打开的xml将一张工作簿复制到另一张工作簿,而无需使用microsoft.interop.excel [英] copy sheets one work book to other work book using open xml with out using microsoft.interop.excel
问题描述
使用打开的xml将一个工作簿复制到另一个工作簿
我想在一个工作簿中将一张工作表中包含的数据复制并粘贴到工作表名称不同的工作簿中,我已经通过使用miscrosoft.interop.excel做到了这一点,我想要使用打开的xml进行相同的操作,请提供解决方案/>
我已经通过使用miscrosoft.interop.excel完成了此操作,这是以下代码,需要使用openxml进行相同的操作,请帮助我
copy sheets one work book to other work book using open xml
i want to copy the data contain in one sheet in one work book and paste into sheet different work book with sheet name, i have done this by using miscrosoft.interop.excel, i want same thing using open xml please give the solution
i have done this by using miscrosoft.interop.excel this is the following code the same thing need to be done using openxml please help me on this
Excel.Application oXL;
Excel.Workbook oWB;
Excel.Worksheet oSheet;
Excel.Range oRange;
oXL = new Excel.Application();
// // Set some properties
oXL.Visible = true;
oXL.DisplayAlerts = false
for (int iWorkbook = 0; iWorkbook < Files.Length; iWorkbook++)
{
if (Files[iWorkbook] != string.Empty)
{
oXL.Workbooks.Add(Files[iWorkbook]);
}
}
for (int i = 2; i <= oXL.Workbooks.Count; i++)
{
int count = oXL.Workbooks[i].Worksheets.Count;
oXL.Workbooks[i].Activate();
for (int j = 2; j <= count; j++)
{
Excel._Worksheet ws = (Excel._Worksheet)oXL.Workbooks[i].Worksheets[j];
ws.Select(Type.Missing);
ws.Cells.Select();
string name = ws.Name;
Excel.Range sel = (Excel.Range)oXL.Selection;
if (sel.Cells.Text != string.Empty)
{
sel.Copy(Type.Missing);
Excel._Worksheet sheet = (Excel._Worksheet)oXL.Workbooks[1].Worksheets.Add(
Type.Missing, Type.Missing, Type.Missing, Type.Missing
);
sheet.Paste(Type.Missing, Type.Missing);
sheet.Name = name;
}
}
}
filepath = filepath + "\\" + TemplateType + ".xlsx";
oWB.SaveAs(filepath, Excel.XlFileFormat.xlWorkbookDefault,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Excel.XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
oWB.Close(Type.Missing, Type.Missing, Type.Missing);
oWB = null;
oXL.Quit();
添加了代码块[/编辑]
Code block added[/Edit]
推荐答案
您可能已经找到 ^ ]可以很容易地从Google获得.
You could have found this page[^] quite easily from Google.
这篇关于使用打开的xml将一张工作簿复制到另一张工作簿,而无需使用microsoft.interop.excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!