首先,我这引用的是microsoft word 11.0 oject library
代码如下:
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;// 打开文件
Type docsType = docs.GetType();
object fileName = "C:\\Documents and Settings\\Administrator\\桌面\\hehe\\a.doc";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
Word.Paragraphs wparas = doc.Paragraphs;
Word.Paragraph wp;
怎样用wparas给wp赋值啊?
/?????
wp = wparas.First;
wp= wparas.First.Next(ref object count);(这个参数是个啥啊);
wp = wparas.Last;
?????/
除了上面这种方法还有别的方法吗?
代码如下:
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;// 打开文件
Type docsType = docs.GetType();
object fileName = "C:\\Documents and Settings\\Administrator\\桌面\\hehe\\a.doc";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
Word.Paragraphs wparas = doc.Paragraphs;
Word.Paragraph wp;
怎样用wparas给wp赋值啊?
/?????
wp = wparas.First;
wp= wparas.First.Next(ref object count);(这个参数是个啥啊);
wp = wparas.Last;
?????/
除了上面这种方法还有别的方法吗?
Word.Document doc = .....//用open()也好,用InvokeMember也好,反正弄一Word.Document
Word.Paragraphs wps= doc.Paragraphs;
string text = "";
long pcount = wps.Count;
Word.Paragraph wp = doc.Paragraphs.First;
text = wp.Range.Text;
for(int i=2;i<=pcount;i++)
{
object obj = (object)(i-1);
Word.Paragraph wp1;
wp1 = wp.Next(ref obj);
Word.Range wr = wp1.Range;
text += wr.Text;
}//后来的做法
Word.Document doc = .....//用open()也好,用InvokeMember也好,反正弄一Word.Document
Word.Paragraphs wps= doc.Paragraphs;
string text = "";
string text="";
object start = 0;
object end = doc.Characters.Count;
Word.Range wr= doc.Range(ref start,ref end);
text = wr.Text;
本人比较笨,以上两种方法都只能获取到换行(/r),段落中Tab(/t),表示表格的(/a),无法获取文字大小、文字首行缩近、表格框架和图片等(其他的我暂时没试)。如果哪位GGJJDDMM有更好的方法,请赐教。