想把WORD模板的内容(包括格式)用程序取出来,显示在编辑器里(如FreeTextBox里)来编辑WORD模板 用的代码如下
using System.Text;
using System.IO;
using Word;
using System.Reflection;
....
string WordPhysicsPath = @"F:\WebSite1\test.doc";
ApplicationClass app = new ApplicationClass();
object fileName = WordPhysicsPath;
object optional = Missing.Value;
object visible = true;
if (File.Exists(WordPhysicsPath))
{
Word.Document doc = app.Documents.Open(ref fileName, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref visible, ref optional, ref optional, ref optional);
object first = 0;
object units = WdUnits.wdCharacter;
object last = doc.Characters.Count; this.txtContent.Text = doc.Range(ref first, ref last).Text;
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
app.Quit(ref saveChanges, ref originalFormat, ref routeDocument); }
这样只是取到了文字内容,没有格式,怎么可以把WORD原样格式和内容显示在编辑器里呢?
using System.Text;
using System.IO;
using Word;
using System.Reflection;
....
string WordPhysicsPath = @"F:\WebSite1\test.doc";
ApplicationClass app = new ApplicationClass();
object fileName = WordPhysicsPath;
object optional = Missing.Value;
object visible = true;
if (File.Exists(WordPhysicsPath))
{
Word.Document doc = app.Documents.Open(ref fileName, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref visible, ref optional, ref optional, ref optional);
object first = 0;
object units = WdUnits.wdCharacter;
object last = doc.Characters.Count; this.txtContent.Text = doc.Range(ref first, ref last).Text;
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
app.Quit(ref saveChanges, ref originalFormat, ref routeDocument); }
这样只是取到了文字内容,没有格式,怎么可以把WORD原样格式和内容显示在编辑器里呢?
解决方案 »
- webBrowser 获取 iframe 元素?
- asp mvc记录用户登录信息的问题
- ISBN图书查询
- 赋予 类型 'varchar' 的大小(9545)超过了任意数据类型的最大允许值(8000) 如何处理??
- 关于调试
- ASP.net SQL分页的问题
- 同样的ASP.NET 源码,在一个机子上可以打开,另一个打开却说我没有权限?
- 请问大家,Jscript.net能否写asp.net的codebehind部分的代码
- 怎么样把两个ArrayList合并成一个??我在文档里找了半天也没找到!急~~!!!!!!!
- 我看到beta1的资料说page.Navigate可以实现页面跳转,但是在beta2下面却不行,请问在beta2下面,什么实现页面跳转?
- 服务器控件button的onclick调用客户端脚本的问题
- 路径问题请教
要求word模板象html模板那样 可以在页面上编辑并保存模板~~~~~~~~~~,非要这样搞,俺也没法,直接下载修改,上传保存多好搞
代码并不多 添加个interop.word.dll 一般都知道的,晚上整理下 贴出来,继续搞下
谢谢各位关注!