C#基础问题.. 本帖最后由 xinxin1982 于 2010-04-29 17:02:46 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个问题请看http://www.csharp360.com/bbs/viewthread.php?tid=142&extra=page%3D1 const string missing = Type.Missing; Microsoft.Office.Interop.Excel.Application myexcel; Microsoft.Office.Interop.Excel.Workbook mybook; Microsoft.Office.Interop.Excel.Worksheet mysheet; string strFile; if (this.myexcel != null) { myexcel = null; } //实例化myexcel对象 myexcel = new Microsoft.Office.Interop.Excel.ApplicationClass(); //打开目标文件outputFile mybook = myexcel.Workbooks.Open(strFile, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //设置第一个工作溥 mysheet = (Microsoft.Office.Interop.Excel.Worksheet)mybook.Sheets.get_Item(1); //激活当前工作溥 mysheet.Activate(); //你的操作 //保存目标文件 mybook.Save(); //释放对象 mysheet = null; mybook = null; myexcel = null; 推荐 你用c# 4.0 COM的互操作性也被提高了。以后不用再写如下丑陋的代码:C# codevar excelApp = new Excel.Application();// . . .excelApp.get_Range("A1", "B4").AutoFormat( Excel.XlRangeAutoFormat.xlRangeAutoFormatTable3, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 现在只需这么写就搞定了:C# code excelApp.Range["A1", "B3"].AutoFormat( Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2); 顺带一句,这段代码用到了另一个叫做“索引属性”的新特性,更多关于这个特性的信息可以参考http://msdn.microsoft.com/en-us/library/ee310208%28VS.100%29.aspx 这个特性只能用于COM互操作上,你不能创建自己的索引属性。 3楼的...谢谢...但是我前面就是把这些放到一个cs文件中实现的...觉得很不好...所以打算分成file,sheet,range等.cs..这样后怎么实现呢...4楼...谢谢...好容易才给大家换了win7...有了.net 3.5...又要弄4.0...还得等等把... 我的问题貌似还是没描述清楚...最刚开始.我如3楼所做...写在一个cs文件里面.然后编译成一个dll或者写成函数模式.如2楼所做..我现在是分成多个cs文件.比方说sheet.cs range.cs excel.cs..然后编译成一个dll..为了后期方便,打算分开.但是出现了1楼我说的问题...用excel 例子只是打个比方..貌似像zedgraph那样的整合dll依次来实现..myexcel.open(xxxxx);myexcel.worksheet.open(1);myexcel.range.read("A1"); 现在我也不知道是什么回事,自己都不知道哪些组件怎么用,书上的带代码在Microsoft visual studio 2005中不能实现 用多态感觉比较好!这样就不需要直接知道定义的属性了!~只需要在类中return返回你所需要的属性 ODBC是不是不能采用多线程编程? 想问下C#控制台输出可以居中吗? 一个简单sql语句怎么写?? 在C#中获取当前时间的函数是什么? c#如何操作 xml:声明空间问题 在c#中如何使用随机数。在线等待,谢谢了 用C#写C/S好吗(假设机器配置够用的情况下)? Visual Studio 的问题!!! 又一个简单问题 谁能告诉我如何隐藏桌面上的图标??? c# 中客户端与服务器连接问题 c# Ftp 访问中文路径无法获取文件 服务器是Linux系统
http://www.csharp360.com/bbs/viewthread.php?tid=142&extra=page%3D1
const string missing = Type.Missing;
Microsoft.Office.Interop.Excel.Application myexcel;
Microsoft.Office.Interop.Excel.Workbook mybook;
Microsoft.Office.Interop.Excel.Worksheet mysheet;
string strFile;
if (this.myexcel != null)
{
myexcel = null;
}
//实例化myexcel对象
myexcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
//打开目标文件outputFile
mybook = myexcel.Workbooks.Open(strFile, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
//设置第一个工作溥
mysheet = (Microsoft.Office.Interop.Excel.Worksheet)mybook.Sheets.get_Item(1);
//激活当前工作溥
mysheet.Activate();
//你的操作
//保存目标文件
mybook.Save();
//释放对象
mysheet = null;
mybook = null;
myexcel = null;
C# code
var excelApp = new Excel.Application();
// . . .
excelApp.get_Range("A1", "B4").AutoFormat(
Excel.XlRangeAutoFormat.xlRangeAutoFormatTable3,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing); 现在只需这么写就搞定了:
C# code
excelApp.Range["A1", "B3"].AutoFormat(
Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2); 顺带一句,这段代码用到了另一个叫做“索引属性”的新特性,更多关于这个特性的信息可以参考http://msdn.microsoft.com/en-us/library/ee310208%28VS.100%29.aspx 这个特性只能用于COM互操作上,你不能创建自己的索引属性。
觉得很不好...所以打算分成file,sheet,range等.cs..这样后怎么实现呢...4楼...谢谢...好容易才给大家换了win7...有了.net 3.5...又要弄4.0...还得等等把...
最刚开始.我如3楼所做...写在一个cs文件里面.然后编译成一个dll
或者写成函数模式.如2楼所做..我现在是分成多个cs文件.比方说sheet.cs range.cs excel.cs..然后编译成一个dll..
为了后期方便,打算分开.但是出现了1楼我说的问题...
用excel 例子只是打个比方..貌似像zedgraph那样的整合dll依次来实现..
myexcel.open(xxxxx);
myexcel.worksheet.open(1);
myexcel.range.read("A1");
这样就不需要直接知道定义的属性了!~
只需要在类中return返回你所需要的属性