何为读取。如果是打开的。那么就必须得安装OFFICE。建议使用2010的版本。安装之后就会有WORD这个软件了。
1:将下载好的安装包进行解压,然后点击“setup.exe”这个文件
2:勾选“我接受此协议的条款”至于条款的内容要不要仔细看,有用户自行决定,勾选好之后点击“继续”
3:在这里呢,用户如果要直接选择立即安装也可以,不过小编在这里呢还是建议用户先选择自定义安装,自行选择安装的路径,如果不选择,软件是会自动帮你安装到电脑的系统盘上的,这样可能日后会影响到电脑的运行速度,选择好之后点击“立即安装”
4:开始安装,安装的时间可能过长,请各位耐心等候
5:安装完成,点击“关闭”即可
office2010破解版:http://www.3322.cc/soft/201509031749.html
WORD文档无法读取,文本可能被破坏,这种情况如何处理?能否进行文本恢复?
打开那个文件,在“工具”——“选项”——“常规”里,选中 常规选项 里的“打开时确认转换”,确认,退出此对话框。
再在“文件”——“打开”中 选中 要打开修复的文件(千万不要直接打开!),在右下角的“打开”按钮旁边有个下三角,点开,选中“打开并修复”。这时打开的就是好的了!
这是实际操作之后的,经验之谈,希望有用!
c#读取Word文本并用html页面方式显示出来
测试成功,分享给你
先添加COM引用:
Microsoft Word 12.0 Object Library
示例代码
using System;
using System.Collections.Generic;
using System.Text;
using MSWord = Microsoft.Office.Interop.Word;
using System.IO;
using System.Reflection;
namespace WordProcesser
{
class Program
{
static void Main(string[] args)
{
MSWord.Application wordApp;
MSWord.Document wordDoc;
Object Nothing = Missing.Value;
Console.WriteLine("Input path:");
Object path = Console.ReadLine();
path = @"E:\mobile.docx";
wordApp = new MSWord.ApplicationClass();
wordDoc = wordApp.Documents.Add(ref path, ref Nothing, ref Nothing, ref Nothing);
object format = MSWord.WdSaveFormat.wdFormatFilteredHTML;
Object newPath = @"E:\mobile.html";
wordDoc.SaveAs(ref newPath, ref format, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
Console.WriteLine("Created!");
}
}
}
这里实现了把word转成html的功能,要显示的话直接调用浏览器或者写个winform里面加个webbrowser控件来显示网页页面。
如何用c#读取word中的某一段文字
三种方法:
一是直接读取.doc文档,可以将所有的文本读入到字符串中在做相关处理:
C# code?
1
2
3
using System.IO;
string temp = System.IO.File.OpenText(@“D:\word.doc”).ReadToEnd();//读取doc文档
二是通过调用.NET对于Office的COM组件来做:
C# code?
1
2
3
4
5
6
7
8
9
10
11
12
13
using Microsoft.Office.Interop.Word;
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();//打开word程序
Microsoft.Office.Interop.Word.Document doc = null;//实例化一个新的word文档
object unknow = Type.Missing;
app.Visible = true;
doc = app.Documents.Open(ref fileName,
ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,
ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,
ref unknow,ref unknow,ref unknow,ref unknow,ref unknow);
string temp = doc.Content.Text.Trim();//将全篇内容存入字符串中,也可以调用别的方法,具体可以查询MSDN...
三是将Word转为XML,可以根据要求提取内容,包括标题,目录等等~~
C# code?
1
2
3
4
5
6
7
8
9
10
11
using System.XML;
XmlDocument doc = new XmlDocument();
doc.Load(filePath); //载入XML文档
XmlElement root = doc.DocumentElement; //定义载入XML的根节点
foreach(XmlNode xn1 in root.ChildNodes) //对于根节点以外的子节点做循环,以下同理
{
//对元素处理~~~
}
http://bbs.csdn.net/topics/280041104
目前兼容 Word 最好的 Web 富文本编辑器是哪一个
富文本格式(Rich Text Format, 一般简称为RTF)是一种跨平台文档格式,由微软公司开发。大多数的文字处理软件都能读取和保存RTF文档。
富文本格式是一种类似DOC格式(Word文档)的文件,有很好的兼容性,使用Windows系统里面的“写字板”就能打开并进行编辑。RTF是一种非常流行的文件结构,很多文字编辑器都支持它。一般的格式设置,比如字体和段落设置,页面设置等等信息都可以存在RTF格式中能在一定程度上实现word与wps文件之间的互访。
一个RTF文件由未格式化文本、控制字、控制符号和组组成。为了更容易的转换,一个标准的RTF文件应该仅包含7位ASCII码字符,RTF文件没有限制文件的行的最大长度。
.net 怎么 读取word文档的内容
//传文档所在路径 返回文档内容
public string Doc2Text(string docFileName)
{
//实例化COM
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object fileobj = docFileName;
object nullobj = System.Reflection.Missing.Value;
//打开指定文件(不同版本的COM参数个数有差异,一般而言除第一个外都用nullobj就行了)
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref fileobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj
);
//取得doc文件中的文本
string outText = doc.Content.Text;
//关闭文件
doc.Close(ref nullobj, ref nullobj, ref nullobj);
//关闭COM
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
//返回
return outText;
}
当然 在读取的时候会有损坏的文件 和被加密的文件等问题 总之C#和office的兼容性不太好
试明白了记得给分 别忘了要引用word的dll
引用文件夹 右键添加引用 在组件里找Microsoft.Office.Interop.Word
怎么用VC读取Word文本框中的内容?
vc6测试成功,写的有点乱你自己好好看看吧.
_Application app;
Documents docs;
_Document doc;
Tables WordTables;
Table WordTable;
Cell WordCell;
Range WordRange;
Columns WordCols;
Rows WordRows;
if(!app.CreateDispatch("Word.Application"))
{
MessageBox("创建Word服务失败!",_T("提示"),MB_ICONERROR);
return;
}
docs.AttachDispatch(app.GetDocuments());
app.SetVisible(true);
//打开文件
IDispatch *dispatch=docs.Open(&_variant_t(_T("d:\\test.doc")),&vtMissing,&vtMissing,&vtMissing,
&vtMissing,&vtMissing,&vtMissing,&vtMissing,&vtMissing,&vtMissing,&vtMissing,
&vtMissing,&vtMissing,&vtMissing,&vtMissing);
if(dispatch)
{
doc.AttachDispatch(dispatch);
}
else
{//出错了
CString szErr="";
szErr.Format("打开文件出错,请查看文件是否存在!");
::AfxMessageBox(szErr);
//退出程序,释放对象
app.Quit(&vtMissing,&vtMissing,&vtMissing);
docs.ReleaseDispatch();
app.ReleaseDispatch();
return;
}
dispatch=doc.GetTables();
if(dispatch)
{
WordTables.AttachDispatch(dispatch);
}
else
{//出错了
CString szErr="";
szErr.Format("取得表格集合出错!");
::AfxMessageBox(szErr);
//退出程序,释放对象
app.Quit(&vtMissing,&vtMissing,&vtMissing);
docs.ReleaseDispatch();
app.ReleaseDispatch();
doc.ReleaseDispatch();
return;
}
int nTableCount=WordTables.GetCount();
if(nTableCount>0)
{
for(int i=1;i<=nTableCount;i++)
{
WordTable.AttachDispatch(WordTables.Item(i));
WordCols.AttachDispatch(WordTable.GetColumns());
WordRows.AttachDispatch(WordTable.GetRows());
int nCols=WordCols.GetCount();
int nRows=WordRows.GetCount();
for(int j=1;j<=nRows;j++)
{
for(int k=1;k<=nCols;k++)
{
dispatch=WordTable.Cell(j,k);
WordRange.AttachDispatch(dispatch);
CString szText=WordRange.GetText();
this->MessageBox(szText);
}
}
}
}
app.Quit(&vtMissing,&vtMissing,&vtMissing);
doc.ReleaseDispatch();
docs.ReleaseDispatch();
app.ReleaseDispatch();
富文本编辑器内容实现word导出下载,请各位大神们指点,感激不尽
1、环境支持
1.1 添加poi支持:包下载地址http://www.apache.org/dyn/closer.cgi/poi/release/
1.2 POI对Excel文件的读取操作比较方便,POI还提供对Word的DOC格式文件的读取。但在它的发行版本中没有发布对Word支持的模块,需要另外下载一个POI的扩展的Jar包。下载地址为http://www.ibiblio.org/maven2/org/textmining/tm-extractors/0.4/ 下载extractors-0.4_zip这个文件
package com.ray.poi.util;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.textmining.text.extraction.WordExtractor;
/**
* 读写doc
* @author wangzonghao
*
*/
public class POIWordUtil {
/**
* 读入doc
* @param doc
* @return
* @throws Exception
*/
public static String readDoc(String doc) throws Exception {
// 创建输入流读取DOC文件
FileInputStream in = new FileInputStream(new File(doc));
WordExtractor extractor = null;
String text = null;
// 创建WordExtractor
extractor = new WordExtractor();
// 对DOC文件进行提取
text = extractor.extractText(in);
return text;
}
/**
* 写出doc
* @param path
* @param content
* @return
*/
public static boolean writeDoc(String path, String content) {
boolean w = false;
try {
// byte b[] = content.getBytes("ISO-8859-1");
byte b[] = content.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();
DocumentEntry de = directory.createDocument("WordDocument", bais);
FileOutputStream ostream = new FileOutputStream(path);
fs.writeFilesystem(ostream);
bais.close();
ostream.close();
} catch (IOException e) {
e.printStackTrace();
}
return w;
}
}
测试
package com.ray.poi.util;
import junit.framework.TestCase;
public class POIUtilTest extends TestCase {
public void testReadDoc() {
try{
String text = POIWordUtil.readDoc("E:/work_space/poi/com/ray/poi/util/demo.doc");
System.out.println(text);
}catch(Exception e){
e.printStackTrace();
}
}
public void testWriteDoc() {
String wr;
try {
wr = POIWordUtil.readDoc("E:/work_space/poi/com/ray/poi/util/demo.doc");
boolean b = POIWordUtil.writeDoc("c:\\demo.doc",wr);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
转载请注明出处51数据库 » 富文本读取word 怎样读取word文本