请问C#如何将一个EXCEL中的SHEET直接拷贝到另一个EXCEL文件的SHEET中呢?(相当的急!)

fivehun 2006-11-10 05:06:12
如何将一个EXCEL中的SHEET直接拷贝到另一个EXCEL文件的SHEET中呢?
请指教!
...全文
1821 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
peilianhai 2006-12-07
  • 打赏
  • 举报
回复
Dim exl As New Excel.ApplicationClass
Dim ebook As Excel.Workbook
ebook = exl.Workbooks.Open("C:\Documents and Settings\Administrator\桌面\a.xls")
Dim ebook2 As Excel.Workbook
ebook2 = exl.Workbooks.Open("C:\Documents and Settings\Administrator\桌面\b.xls")
exl.Visible = True
ebook.Worksheets.Copy(, ebook2.Worksheets.Item("Sheet1"))
没有问题啊?
参考下这个
zhaochong12 2006-12-06
  • 打赏
  • 举报
回复
http://lucky_elove.www1.dotnetplayground.com/ShowDetail.aspx?id=C673E2CD-3F1E-4919-8CE0-D69B894A0599

http://lucky_elove.www1.dotnetplayground.com/ShowDetail.aspx?id=BF0A54F9-C7C7-4200-BD9A-802AC1F5DE50
yuyyu2016 2006-12-06
  • 打赏
  • 举报
回复
mark
livode 2006-11-20
  • 打赏
  • 举报
回复
复制sheet见
http://msdn2.microsoft.com/zh-CN/library/ms178800.aspx
smartstar2005 2006-11-20
  • 打赏
  • 举报
回复
Mark
livode 2006-11-20
  • 打赏
  • 举报
回复
这是一个按钮的代码,功能:将你选的第一个文件的sheet1复制到你选的第二个文件的最前面.环境:office2000+.net2003
private void button5_Click(object sender, System.EventArgs e)
{
this.openFileDialog1.Title = "请选择源文件";
this.openFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
this.openFileDialog1.ShowDialog();

if(this.openFileDialog1.FileName.Equals(""))
{
MessageBox.Show("请选择一个Excel文件!");
}
else
{
Excel.Application excel = new Excel.ApplicationClass();
Excel.Workbook workbook = excel.Workbooks.Open(this.openFileDialog1.FileName,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);

this.openFileDialog1.Title="请选择目标文件";
this.openFileDialog1.ShowDialog();

if(this.openFileDialog1.FileName.Equals(""))
{
MessageBox.Show("请选择一个Excel文件!");
}
else
{
Excel.Workbook workbook1 = excel.Workbooks.Open(this.openFileDialog1.FileName,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.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets["Sheet1"];
worksheet.Copy(workbook1.Sheets["sheet1"],Type.Missing);
workbook1.Save();
workbook1.Close(false,Type.Missing,Type.Missing);
}
workbook.Save();
workbook.Close(false,Type.Missing,Type.Missing);
}
}
fivehun 2006-11-10
  • 打赏
  • 举报
回复
string OutFile = CPubData._OutExcelFilePathName;
if(File.Exists(OutFile))
File.Delete(OutFile);
File.Create(OutFile);
fivehun 2006-11-10
  • 打赏
  • 举报
回复
第二个文件,是新建立的,但不知为何
Excel.Application mApp = new Excel.ApplicationClass();
Excel.Workbook m_book1 = mApp.Workbooks.Open(CPubData._SrcExcelFileName,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value ,Missing.Value ,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
Excel.Workbook m_book2 = mApp.Workbooks.Open(CPubData._OutExcelFilePathName,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value ,Missing.Value ,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
mApp.Visible = true;
((Excel._Worksheet)m_book1.Worksheets[1]).Copy(Missing.Value,m_book2.Worksheets[1]);

在第二个文件open时出错。
fivehun 2006-11-10
  • 打赏
  • 举报
回复
谢谢,还有就是不将公式拷贝如何做呢?
peilianhai 2006-11-10
  • 打赏
  • 举报
回复
◎◎
这个好像不难啊,就几条命令的事
不过具体代码我现在写不出来
lizhizhe2000 2006-11-10
  • 打赏
  • 举报
回复
帮顶~!
lytone52 2006-11-10
  • 打赏
  • 举报
回复
http://topic.csdn.net/t/20030621/14/1941643.html

http://topic.csdn.net/t/20041214/14/3643862.html

提供两个线索

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧