111,120
社区成员
发帖
与我相关
我的任务
分享
public bool GetPagePasteFromOpenDoc(int ipage)
{
try
{
Range ra = null;
Range ra_1 = null;
Range ra_2 = null;
object ipage1 = ipage;
object ipage2 = ipage + 1;
// 跳转种类
object objWhat = WdGoToItem.wdGoToPage;
// 跳转位置
object objWhich = WdGoToDirection.wdGoToNext;
Object refmissing = System.Reflection.Missing.Value;
(WordControl.document as Document).Select();
Selection s1 = (WordControl.wd as ApplicationClass).Selection;
s1.Select();
ra = s1.Range;
s1.GoTo(ref objWhat, ref objWhich, ref refmissing, ref ipage1);
ra_1 = s1.Range;
Selection s2 = (WordControl.wd as ApplicationClass).Selection;
s2.GoTo(ref objWhat, ref objWhich, ref refmissing, ref ipage2);
s2.Select();
ra_2 = s2.Range;
if (ra_2.End == ra_1.End)
{
ra.Start = ra_1.End;
ra.End = ra_1.End + 999999999;
}
else
{
ra.Start = ra_1.End;
ra.End = ra_2.End;
}
ra.Select();
ra.Copy();
return true;
}
catch
{
this.Close();
return false;
}
}
Word.ApplicationClass wordApp=new ApplicationClass();
object file=path;
object nullobj=System.Reflection.Missing.Value;
Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data=Clipboard.GetDataObject();
txtFileContent.Text=data.GetData(DataFormats.Text).ToString();
doc.Close();
Function GetPageRange(iPage as Integer) as Range
Set GetPageRange = wd.ActiveDocument.Range(0,0)
Set GetPageRange = GetPageRange.Goto(What:=wdGotoPage, Name:=iPage)
Set GetPageRange = GetPageRange.Goto(What:=wdGotoBookmark, Name:="\Page")
End Function