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 ...
随机推荐
- jsp有哪些内置对象?作用分别是什么?分别有什么方法?
JSP共有以下9个内置的对象: request 用户端请求,此请求会包含来自GET/POST请求的参数 response 网页传回用户端的回应 pageContext 网页的属性是在这里管理 sess ...
- 小说一下case ~
case 这个关键词,用的地方不少~大部分的用途都通过以下的方式去应用 SELECT CASE @i END AS 测试1; 测试1 ----------- DECLARE @Hour INT = D ...
- 烂泥:mysql修改本地主机连接
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 在mysql数据库安装完毕后,为了能远程连接管理mysql数据库.我们一般是在mysql服务器上通过update命令来更新user表中的host记录的. ...
- C语言 时间函数的学习和总结
一直都是以简单的time_t t,time(&t),ctime(&t)来表示时间,后来要以时间为日志文件的名字时,就有点蒙逼了.学习一下. tm结构: struct tm { ...
- CSS background-position 用法详细介绍
语法: background-position : length || length background-position : position || position 取值: length : ...
- WPF之全局快捷键
目录 1.WPF快捷键实现方式 2.全局快捷键设置界面 3.Windows API调用 4.注册全局快捷键 5.快捷键触发 WPF快捷键实现方式 WPF快捷键实现主要有自定义快捷键命令和全局快捷键两种 ...
- Windows Azure IP地址详解
Windows Azure上的IP地址有以下几种: 公网IP地址 VIP ILPIP Reserved IP 内网IP地址 DIP Static IP VIP是动态分配的公网IP,VIP可以被分配到云 ...
- namesilo域名注册教程
一.注册账号 打开http://www.namesilo.com ,我们先去注册一个Namesilo帐号,然后再在Namesilo注册域名!如图: 接下来,就是填写一些简单资料,如图: 然后Names ...
- BZOJ1864[ZJOI2006]三色二叉树[树形DP]
1864: [Zjoi2006]三色二叉树 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 773 Solved: 548[Submit][Status] ...
- Unity 实现物体破碎效果(转)
感谢网友分享,原文地址(How to Make an Object Shatter Into Smaller Fragments in Unity),中文翻译地址(Unity实现物体破碎效果) In ...