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 ...
随机推荐
- 将表里的数据批量生成INSERT语句的存储过程 继续增强版
文章继续 桦仔兄的文章 将表里的数据批量生成INSERT语句的存储过程 增强版 继续增强... 本来打算将该内容回复于桦仔兄的文章的下面的,但是不知为何博客园就是不让提交!.... 所以在这里贴出来吧 ...
- my_strstr()
const char* my_strstr(const char* S1,const char* S2){ int i=0,flag=0; while('\0'!=*(S1+i)){ if(*(S1+ ...
- 描述Linux下软链接和硬链接的区别(计时2分钟)
在linux系统中,链接分两种 :一种被称为硬链接(Hard Link),另一种被称为符号链接或软链接(Symbolic Link). 1)默认不带参数情况下,ln命令创建的是硬链接. 2)硬链接文件 ...
- CentOS6.5搭建LNMP
1:查看环境: ? 1 2 [root@10-4-14-168 html]# cat /etc/redhat-release CentOS release 6.5 (Final) 2:关掉防火墙 ...
- nc分析代理服务器
最近洒家搞了一个代理服务器(参见 折腾阿里云笔记 ).以前ƒq的时候代理服务器都是开在127.0.0.1,浏览器到代理服务器之间不会有中间人监听问题.现在代理服务器不在本机,洒家就突然想到了这些问题: ...
- How to create and apply a patch with Git
Creating a patch file with git is quite easy to do, you just need to see how it’s done a few times. ...
- Linux压缩指令
1.windows系统和Linux系统的压缩文件只有zip格式的是通用的 2.windows系统可以解压几乎所有的Linux压缩格式 3.Linux压缩指令 gzip 指令 格式: gzip 压缩的文 ...
- GDB教程详解
GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具.或许,各位比较喜欢那种图形界面方式的,像VC.BCB等IDE的调试,但如果你是在UNIX平台下做软件,你会发现GDB这个调试工具有比VC ...
- 自定义评分器Similarity,提高搜索体验(转)
文章转自:http://blog.csdn.net/duck_genuine/article/details/6257540 首先说一下lucene对文档的评分规则: score(q,d) = ...
- 结对编程项目——四则运算vs版
结对编程项目--四则运算vs版 1)小伙伴信息: 学号:130201238 赵莹 博客地址:点我进入 小伙伴的博客 2)实现的功能: 实现带有用户界面的四则运算:将原只能在 ...