求C#删除Excel里的Sheet正解 一个Sheet作为程序打印报表的模板,里面有4个Sheet。真正用到的只有1个Sheet,其它3个Sheet要删除。怎么用C#代码完成? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using Excel=Microsoft.Office.Interop.Excel;....... Object refmissing = System.Reflection.Missing.Value; Excel._Application exc = new Excel.ApplicationClass(); exc.Visible = true; Excel.Workbooks workbooks = exc.Workbooks; workbooks._Open("c:\\test.xls",refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing); Excel.Worksheet sheet = (Excel.Worksheet)exc.Worksheets.get_Item(1); sheet.Delete(); exc.Save(refmissing); MessageBox.Show("ok"); 请参见我的bloghttp://linfuguo.cnblogs.com/及下面这个文件http://www.cnblogs.com/linfuguo/articles/462699.html 不行?why不行?报什么错?贴出来看看,应该是可以运行的代码啊 using System;using System.Collections.Generic;using System.Text;using Microsoft.Office.Interop.Excel;namespace exceldemo{ class Program { static void Main(string[] args) { try { Application app = new Application(); app.Visible = true; app.UserControl = true; app.DisplayAlerts = false; Workbooks myworkbooks = app.Workbooks; Workbook myworkbook = myworkbooks.Add(@"C:\Documents and Settings\Administrator\My Documents\我接收到的文件\book.xls"); Worksheet mysheet = (Worksheet)myworkbook.Worksheets.get_Item(1); mysheet.Delete(); myworkbook.Save(); myworkbooks.Application.Save(@"C:\Documents and Settings\Administrator\My Documents\我接收到的文件\book.xls"); //string str = ((Range)mysheet.Cells[1, 1]).Text.ToString(); int i = mysheet.Rows.Count; //Console.WriteLine(myworkbook.Worksheets.Count); app.Quit(); } catch (Exception ex) { } } }}测过了,似乎可以.... C# SQL语句传值的问题 得到局域网内的计算机ip和计算机名 高分求助 时钟是怎么终止? 关于c#写的com/com+组件 时间操作的SQL问题 金额计算百分比问题 DateGrid 中编辑事件 困扰已久的问题了,在线等候答案。 为什么System.Management找不到? 在c# winform中,怎么做类似msn好友上线提示的探出框 用c#从oracle中如何导出数据到foxpro的dbf表中
....... Object refmissing = System.Reflection.Missing.Value;
Excel._Application exc = new Excel.ApplicationClass();
exc.Visible = true;
Excel.Workbooks workbooks = exc.Workbooks;
workbooks._Open("c:\\test.xls",refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing);
Excel.Worksheet sheet = (Excel.Worksheet)exc.Worksheets.get_Item(1);
sheet.Delete();
exc.Save(refmissing);
MessageBox.Show("ok");
http://linfuguo.cnblogs.com/
及下面这个文件
http://www.cnblogs.com/linfuguo/articles/462699.html
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Excel;namespace exceldemo
{
class Program
{
static void Main(string[] args)
{
try
{
Application app = new Application();
app.Visible = true;
app.UserControl = true;
app.DisplayAlerts = false;
Workbooks myworkbooks = app.Workbooks;
Workbook myworkbook = myworkbooks.Add(@"C:\Documents and Settings\Administrator\My Documents\我接收到的文件\book.xls");
Worksheet mysheet = (Worksheet)myworkbook.Worksheets.get_Item(1);
mysheet.Delete();
myworkbook.Save();
myworkbooks.Application.Save(@"C:\Documents and Settings\Administrator\My Documents\我接收到的文件\book.xls");
//string str = ((Range)mysheet.Cells[1, 1]).Text.ToString(); int i = mysheet.Rows.Count;
//Console.WriteLine(myworkbook.Worksheets.Count);
app.Quit();
}
catch (Exception ex)
{
}
}
}
}
测过了,似乎可以....