C#读取word

ontway 2011-08-02 03:42:30
为什么错误提示是:错误 CS0102: 类型“WindowsFormsApplication2.dlWindow”已经包含“openFile”的定义

请各位大侠看看错在哪里,如何修改?小弟不胜感激

public override void openFile(object fileName)
{
try
{

{

object file = openFileDialog1.FileName;

object nullobj = System.Reflection.Missing.Value;

object filename = file;

object confirmConversions = Type.Missing;

object readOnly = Type.Missing;

object addToRecentFiles = Type.Missing;

object passwordDocument = Type.Missing;

object passwordTemplate = Type.Missing;

object revert = Type.Missing;

object writePasswordDocument = Type.Missing;

object writePasswordTemplate = Type.Missing;

object format = Type.Missing;

object encoding = Type.Missing;

object visible = Type.Missing;

object openConflictDocument = Type.Missing;

object openAndRepair = Type.Missing;

object documentDirection = Type.Missing;

object noEncodingDialog = Type.Missing;

object missing = Type.Missing;

Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();

Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref filename,
ref confirmConversions,
ref readOnly,
ref addToRecentFiles,
ref passwordDocument,
ref passwordTemplate,
ref revert,
ref writePasswordDocument,
ref writePasswordTemplate,
ref format,
ref encoding,
ref visible,
ref openConflictDocument,
ref openAndRepair,
ref documentDirection,
ref noEncodingDialog);
}
}
catch (Exception ex)
{
MessageBox.Show("出现错误:" + ex.ToString());
}

private void BtnRead_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
object file = openFileDialog1.FileName;

openFile(file);
readPar(1);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();

IDataObject data = Clipboard.GetDataObject();
doc.Activate();

doc.Close(ref missing, ref missing, ref missing);

richTextBox1.Text = data.GetData(DataFormats.Text).ToString();
}
...全文
76 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fesh004 2011-08-02
  • 打赏
  • 举报
回复
应该是你在那里重复定义了,你得好好查查了
宝_爸 2011-08-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ontway 的回复:]

引用 1 楼 findcaiyzh 的回复:

重复定义openFile了?
我是想先定义openFile,然后在BtnRead_Click中调用函数,如何改?
[/Quote]

错误提示的是openFile重复定义了,看看你代码中是不是Partial类或者其它地方还有openFile的定义。
ontway 2011-08-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 findcaiyzh 的回复:]

重复定义openFile了?
[/Quote]我是想先定义openFile,然后在BtnRead_Click中调用函数,如何改?
jian03112 2011-08-02
  • 打赏
  • 举报
回复
mark
宝_爸 2011-08-02
  • 打赏
  • 举报
回复
重复定义openFile了?

110,534

社区成员

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

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

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