C# Microsoft.Office.Interop.Owc11 导出excel文件

1、新建项SupremeWindowsForms窗体应用项目(项目平台设置称X86)

注意:因为大多数第三方写的COM控件,只支持32位的系统,因此在VS中找到引用控件所在的项目SupremeWindowsForms设置一下,SupremeWindowsForms项目--〉属性--〉生成--〉常规---〉目标平台---〉选择X86即可

否则会出现如下问题:

检索 COM 类工厂中 CLSID 为 {XXXX-XXXX-XXX-XXXXX-XXX} 的组件时失败,原因是出现以下错误: 80040154。

如以上问题出现,多半是因为COM控件未在目标机器上面注册造成的

解决方法:Resvr32 .net中引用控件的名称,如果注册成功,问题不在出现

但是如果是在x64位的系统中,即使控件注册成功,错误依照提示,是因为大多数第三方写的COM控件,只支持32位的系统,

在VS中找到引用控件所在的项目--〉属性--〉生成--〉常规---〉目标平台---〉选择X86即可解决

2、右键添加Microsoft.Office.Interop.Owc11.dll和OWC11.dll组件,下载地址https://download.csdn.net/download/LongtengGensSupreme/12037912

3、添加方法ExportExcel,

代码如下:

按钮事件方法:

private void btnTestchartPrint_Click(object sender, EventArgs e)
{//测试 Microsoft.Office.Interop.Owc11 SpreadsheetClassExportExcel();
}

ExportExcel方法:

public void ExportExcel(){int colNum = 5;int rowNum = 2;SpreadsheetClass xlsheet = null;try{xlsheet = new SpreadsheetClass();}catch{MessageBox.Show("测试Owc11 SpreadsheetClass出错", "测试Microsoft.Office.Interop.Owc11", MessageBoxButtons.OK);try{FileInfo fi = new FileInfo(Path.Combine(Application.StartupPath, "OWC11.dll"));if (fi.Exists){Process p = new Process();p.StartInfo = new ProcessStartInfo("regsvr32", "\"" + fi.FullName + "\"");p.StartInfo.UseShellExecute = false;p.StartInfo.CreateNoWindow = true;p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;p.Start();p.WaitForExit();}}catch{}xlsheet = new SpreadsheetClass();}//xlsheet.Sheets.Add(null, xlsheet.Sheets.Count, null, null);//Worksheet ws = xlsheet.Sheets[0] as Worksheet;//ws.Name = "hello";//xlsheet.ActiveSheet.Name = "";//合并单元格xlsheet.get_Range(xlsheet.Cells[1, 1], xlsheet.Cells[1, colNum]).set_MergeCells(true);xlsheet.ActiveSheet.Cells[1, 1] = "测试Microsoft.Office.Interop.Owc11";//字体加粗xlsheet.get_Range(xlsheet.Cells[1, 1], xlsheet.Cells[1, colNum]).Font.set_Bold(true);//单元格文本水平居中对齐xlsheet.get_Range(xlsheet.Cells[1, 1], xlsheet.Cells[1, colNum]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter);//设置字体大小xlsheet.get_Range(xlsheet.Cells[1, 1], xlsheet.Cells[1, colNum]).Font.set_Size(14);//设置列宽xlsheet.get_Range(xlsheet.Cells[1, 3], xlsheet.Cells[1, 3]).set_ColumnWidth(20);//画边框线xlsheet.get_Range(xlsheet.Cells[1, 1], xlsheet.Cells[rowNum, 9]).Borders.set_LineStyle(XlLineStyle.xlDashDotDot);int x = 2, y = 1;//写入数据  (这里可根据需要由ds生成)for (int row = 2; row < 10; row++)   //注意写入数据时,必须从第一行开始写excel里没有第"0"行{for (int i = 0; i < 5; i++){xlsheet.ActiveSheet.Cells[row, i + 1] = 123.456;}}try{//将数字格式化为金额(要格式化的单元格内的值必须为数值型)xlsheet.get_Range(xlsheet.Cells[2, 1], xlsheet.Cells[10, 15]).set_NumberFormat("¥#,##0.00");xlsheet.Export(Path.Combine(Application.StartupPath, "testowc11.xls"), SheetExportActionEnum.ssExportActionNone, SheetExportFormat.ssExportXMLSpreadsheet);MessageBox.Show("export ok");Process.Start(Path.Combine(Application.StartupPath, "testowc11.xls"));}catch{MessageBox.Show("导出Owc11 SpreadsheetClass出错", "测试Microsoft.Office.Interop.Owc11", MessageBoxButtons.OK);}}

4、测试结果如下

注意事项问题原文链接:https://blog.csdn.net/Fibona/article/details/5949180

C# Microsoft.Office.Interop.Owc11 导出excel文件相关推荐

  1. 未能加载文件或程序集“Microsoft.Office.Interop.Owc11, Version=11.0.0.0, ...”或它的某一个依赖项~[解决方案]...

    配置错误 说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件. 分析器错误信息: 未能加载文件或程序集"Microsoft.Office.I ...

  2. 编程经验:Microsoft.Office.Interop.Owc11 Error

    Microsoft.Office.Interop.Owc11错误 1.未能加载文件或程序集"Microsoft.Office.Interop.Owc11, Version=11.0.0.0, ...

  3. 错误提示“未能加载文件或程序集“Microsoft.Office.Interop.Owc11”,

    .NET错误提示: 未能加载文件或程序集"Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicK ...

  4. 无法引用Microsoft.Office.Interop.Excel的解决

    微软MSDN文章: http://msdn.microsoft.com/zh-cn/library/aa159923(office.11).aspx 下载 在 Microsoft Office 200 ...

  5. C#利用Microsoft.Office.Interop.Excel导出excel文件

    导入Microsoft.Office.Interop.Excel.dll文件引用   为了能够导出excel文件,由于使用的是Microsoft.Office.Interop.Excel,所以我们首先 ...

  6. C#利用Microsoft.Office.Interop.Excel导出数据到Excel

    添加引用(VS2013位于C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\ ...

  7. c#操作excel方式三:使用Microsoft.Office.Interop.Excel.dll读取Excel文件

    1.引用Microsoft.Office.Interop.Excel.dll 2.引用命名空间.使用别名 using System.Reflection; using Excel = Microsof ...

  8. DEV GridControl导入导出Excel文件 - 简单表格数据导入(Microsoft.Office自带)

    1.命名空间 using DevExpress.XtraEditors; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Grid ...

  9. 使用Microsoft.Office.Interop.Excel批量编辑Excel文件

    先看运行结果 → 运行结果 开发环境 Microsoft Visual Studio Community 2019 Microsoft .NET Framework 4.8.04084 Microso ...

最新文章

  1. 在Centos 7下编译openwrt+njit-client
  2. 转载:Linux下查看/修改系统时区、时间
  3. sql年月日24小时制_24小时制的「无码」真人秀,令人叫绝
  4. jzoj3501-消息传递【换根法,树形dp】
  5. 路由总结之静态、RIP、OSPF、IS-IS、BGP和策略路由
  6. 无法安装操作系统,An unexpected error(0) occurred at line 1768 in f:\nt2\base\boot\setup\arcdisp.c....
  7. linux 渗透 密码,linux渗透中常用命令+Tip
  8. 职业经验分享之我是如何转行成为数据分析师的
  9. Vlan和Trank
  10. opencv4 QR码检测和识别源码解析
  11. 三循环流水灯电路的原理
  12. 2023进销存软件排行榜
  13. roscore失败,提示RLException: Unable to contact my own server
  14. python 循环嵌套break continue猜字游戏_Python代码的人机大战(循环嵌套)
  15. 浅谈巫师2的战斗难度策略
  16. 安卓 SDK 开发使用 VirtualAPK 实现插件化
  17. robotframework以手机模式打开浏览器
  18. 根据哪些参数选择石英晶体谐振器
  19. git使用指南_git设计师指南
  20. python ftp上传/下载文件,带进度条显示

热门文章

  1. 4位BCD计数器Verillog简便代码-无需例化子模块
  2. 基于圆展开自适应三边测量算法的室内定位
  3. Linux系统解决OSDLyrics搜索显示的中文歌词名乱码问题
  4. python--计数算法
  5. CET-6 Word’s defination from Oxford dictionary 大学英语六级词汇剑桥英文释义
  6. html/css实现居中的几个常用方法
  7. Paraview Programmable filter
  8. C++编写MC(含源码)
  9. Linux 入门——基础使用及常见命令
  10. 数据结构用递归算法计算二叉树中叶子结点数目的思想c语言程序,编写递归算法计算二叉树中叶子结点的数目。.doc...