Word Excel 操作总结
1.与office无关使用 Aspose.Cells.dll,Aspose.Words.dll
2.使用Microsoft.Office.Interop.Excel Microsoft.Office.Interop.Word
3.打开文件
WORD:
object oMissing = Missing.Value;
_Application app = new Application();
_Document currentDoc = null;
app.Visible = false;
currentDoc = app.Documents.Open(filePath, ref oMissing, ref oMissing, ref oMissing);
//currentDoc = app.Documents.Add(templatesDirectory,ref oMissing, ref oMissing, ref oMissing); //打开模版
EXCEL:
var app = new Application();
app.Visible = false;
var workbooks = app.Workbooks;
var workbook = workbooks.Open(filePath);
//var workbook = workbooks.Add(templatePath); //打开模版
var sheets = workbook.Sheets;
var sheet = (_Worksheet)sheets.get_Item(1);
4.保存或另存文件
Excel:
app.DisplayAlerts = false;
app.ActiveWorkbook.SaveAs(filePath,
XlFileFormat.xlWorkbookNormal,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
XlSaveAsAccessMode.xlExclusive,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
WORD:
object oMissing = Missing.Value;
object oFileName = fileName;
object oFormat = WdSaveFormat.wdFormatDocument;
object oAddToRecentFiles = false;
currentDoc.SaveAs(
ref oFileName, ref oFormat, ref oMissing, ref oMissing, ref oAddToRecentFiles,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
5.退出文件:
WORD:
object oSave = false;
currentDoc.Close(ref oSave, ref oMissing, ref oMissing);
Object nothing = Missing.Value;
app.Quit(ref nothing, ref nothing, ref nothing);
Excel:
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
IntPtr t = new IntPtr(app.Hwnd);
int k = 0;
GetWindowThreadProcessId(t, out k);
Process p = Process.GetProcessById(k);
p.Kill();
6.word 复制表格,插入分页符并黏贴
currentDoc.Tables[1].Select();
app.Selection.Copy();
object mymissing = Missing.Value;
object myunit = WdUnits.wdStory;
app.Selection.EndKey(ref myunit, ref mymissing);
object pBreak = (int)WdBreakType.wdPageBreak;
app.Selection.InsertBreak(ref pBreak);
app.Selection.Paste();
Word Excel 操作总结的更多相关文章
- Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件
Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件,用这个控件来导入.导出数据非常方便.其中Aspose.Cells就是用来操作Excel的,功能有很多.我所用的是最基本的 ...
- Java操作word文档使用JACOB和POI操作word,Excel,PPT需要的jar包
可参考文档: http://wibiline.iteye.com/blog/1725492 下载jar包 http://download.csdn.net/download/javashixiaofe ...
- C#Aspose操作Word & Excel简版(后会研究补充更多功能)
利用Aspose操作Word & Excel首先要在项目中标引用Aspose.Words.dll和Aspose.Cells.dll. 首先说一说向Word中写入数据,目前做的是向Word中的标 ...
- Npoi导入导出Excel操作
之前公司的一个物流商系统需要实现对订单的批量导入和导出,翻阅了一些资料,最后考虑使用NPOI实现这个需求. 在winform上面实现excel操作:http://www.cnblogs.com/Cal ...
- ruby中 Win32ole的各应用操作方法(word excel Outlook IE)
Win32ole为标准Ruby发行版的一部分.Win32ole是访问Windows自动化的接口,可以让Ruby和Windows应用进行交互.具体说来Win32ole可以操作Word,Excel,IE, ...
- ASP.NET Word/Excel 权限问题
在部署Word/Excel到服务器的时候,经常会碰到权限问题.例如; Retrieving the COM class factory for component with CLSID {0002 ...
- Atitit.office word excel ppt pdf 的web在线预览方案与html转换方案 attilax 总结
Atitit.office word excel ppt pdf 的web在线预览方案与html转换方案 attilax 总结 1. office word excel pdf 的web预览要求 ...
- c#开源Excel操作库--NPOI
前言 以前也用C#操作过excel,用的是OleDb或者offic的com组件,但是总是非常的麻烦,依赖限制较多,所以果断寻找开源方案,JAVA上面已经有非常成熟的POI,就这样,找到了移.Net的移 ...
- PDF/WORD/EXCEL 图片预览
一.PDF/WORD/EXCEL 转 XPS 转 第一页内容 转 图片 WORD.EXCEL转XPS (Office2010) public bool WordToXPS(string sourceP ...
随机推荐
- Java里面的转义字符
转义字符是指,用一些普通字符的组合来代替一些特殊字符,由于其组合改变了原来字符表示的含义,因此称为“转义”. 常见的转义字符: \n 回车(\u000a) \t 水平制表符(\u0009) \b 空格 ...
- [转]使用Oracle SQL Developer 17410 提示无法从套接字获取更多数据如何解决
本文转自:http://m.educity.cn/ite/1121475.html 将oracle?安装目录下的Network/admin/listener.ora文件中的 (PROGRAM = ex ...
- js获取鼠标位置的各种方法
在一些DOM操作中我们经常会跟元素的位置打交道,鼠标交互式一个经常用到的方面,令人失望的是不同的浏览器下会有不同的结果甚至是有的浏览器下没结果,这篇文章就上鼠标点击位置坐标获取做一些简单的总结,没特殊 ...
- UESTC-第五届ACM趣味程序设计竞赛第四场(正式赛)--不完全解题报告
比赛链接: http://acm.uestc.edu.cn/contest.php?cid=230 A.Police And The Thief ---UESTC 1913 简单博弈,先假设在警察先走 ...
- POJ1837 Balance[分组背包]
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13717 Accepted: 8616 Descript ...
- POJ3666Making the Grade[DP 离散化 LIS相关]
Making the Grade Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6445 Accepted: 2994 ...
- 网页下载Google Play 的App
前言 当你想在google play上下载某个应用,而无奈手机的系统并没有安装google servicess,此刻是否有些捉急? 本文分享的是一个网站,它可以无需手机而直接通过网页下载Google ...
- 邮件页面为何只能Table写及注意事项
编写HTML邮件与编写HTML页面有很大的不同.因为,各面向网民的主流邮箱都或多或少的会对它们接收到的HTML邮件在后台进行过滤.毫无疑问,JS代码是被严格过滤掉的,包括所有的事件监听 属性,如onc ...
- 转: Git远程操作详解 (阮一峰)
说明: 通过这个说明终于把远程操作给搞明白了. http://www.ruanyifeng.com/blog/2014/06/git_remote.html
- ORACLE临时表总结(转载)
转载地址:http://www.cnblogs.com/kerrycode/p/3285936.html 临时表概念 临时表就是用来暂时保存临时数据(亦或叫中间数据)的一个数据库对象,它和普通表有些类 ...