C# word内容复制 100分,不够再加!

YorHoHo 2009-12-10 06:45:38
c#,怎样将word的每页的内容循环的复制到剪贴板!
使用的是Microsoft.Office.Interop.Word!
谢谢!
...全文
389 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
TimDavid 2010-01-15
  • 打赏
  • 举报
回复
r1,r2,s1,s2糟糕的代码?
YorHoHo 2009-12-11
  • 打赏
  • 举报
回复
up
YorHoHo 2009-12-11
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 dobzhansky 的回复:]
友情帮顶,
感觉
没有插入分页符的页面数, 是计算出来的
[/Quote]

没有插入分页符的页面数已经拿到了,就是取每页内容的时候有点问题!
Dobzhansky 2009-12-11
  • 打赏
  • 举报
回复
友情帮顶,

感觉
没有插入分页符的页面数, 是计算出来的

YorHoHo 2009-12-11
  • 打赏
  • 举报
回复
没人回答么?现在是数据取不全,次序混乱!!
YorHoHo 2009-12-11
  • 打赏
  • 举报
回复
up……数据还是取不全,总是有一页数据取不到!
wjy217213 2009-12-11
  • 打赏
  • 举报
回复
友情UP一下!
mzy939216 2009-12-11
  • 打赏
  • 举报
回复
新人路过,up一下!
jin20000 2009-12-11
  • 打赏
  • 举报
回复
帮顶
YorHoHo 2009-12-11
  • 打赏
  • 举报
回复
问题解决!贴上代码供大家参考!

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;
}
}
grzx2210 2009-12-10
  • 打赏
  • 举报
回复
up
YorHoHo 2009-12-10
  • 打赏
  • 举报
回复
up上去
YorHoHo 2009-12-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 findcaiyzh 的回复:]
引用 3 楼 yorhoho 的回复:
引用 2 楼 findcaiyzh 的回复:

于获得指定页,请参照如下VBA函数
VB codeFunction  GetPageRange(iPageasInteger)as  RangeSet  GetPageRange=  wd.ActiveDocument.Range(0,0)Set  GetPageRange=  GetPageRange.Goto(What:=wdGotoPage,  Name:=iPage)Set  GetPageRange=  GetPageRange.Goto(What:=wdGotoBookmark,  Name:="\Page")EndFunction


要的就是下面VBA的那段代码,但是不行!!


好像你需要插入换页符。

否则没有办法取得某一页,因为,页面设置会影响页数和页码
[/Quote]

对…………现在就是第一页取不到!!
宝_爸 2009-12-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yorhoho 的回复:]
引用 2 楼 findcaiyzh 的回复:

于获得指定页,请参照如下VBA函数
VB codeFunction  GetPageRange(iPageasInteger)as  RangeSet  GetPageRange=  wd.ActiveDocument.Range(0,0)Set  GetPageRange=  GetPageRange.Goto(What:=wdGotoPage,  Name:=iPage)Set  GetPageRange=  GetPageRange.Goto(What:=wdGotoBookmark,  Name:="\Page")EndFunction


要的就是下面VBA的那段代码,但是不行!!
[/Quote]

好像你需要插入换页符。

否则没有办法取得某一页,因为,页面设置会影响页数和页码
wuyq11 2009-12-10
  • 打赏
  • 举报
回复
public override void openFile(object fileName){} //打开文档
public override object readPar(int i){} //读取word文档的第i段
private string ReadWord(string path)
{
string str = string.Empty;
Document myWordDoc;
Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object filepath = path;
object oMissing = Missing.Value;
myWordDoc = myWordApp.Documents.Open(ref filepath, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
str = myWordDoc.Content.Text;
return str;
}

YorHoHo 2009-12-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 findcaiyzh 的回复:]

于获得指定页,请参照如下VBA函数
VB codeFunction GetPageRange(iPageasInteger)as RangeSet GetPageRange= wd.ActiveDocument.Range(0,0)Set GetPageRange= GetPageRange.Goto(What:=wdGotoPage, Name:=iPage)Set GetPageRange= GetPageRange.Goto(What:=wdGotoBookmark, Name:="\Page")EndFunction
[/Quote]

要的就是下面VBA的那段代码,但是不行!!
宝_爸 2009-12-10
  • 打赏
  • 举报
回复
C#读取word的代码

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();



于获得指定页,请参照如下VBA函数

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

YorHoHo 2009-12-10
  • 打赏
  • 举报
回复
up^^

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧