0

你好

我在 C# 中有一个面板,比如 panel2,其中包含一些文本框、按钮、标签和图片框。它还包含一个内部滚动属性为 true 的数据网格视图。我希望在一个简单的按钮单击事件上创建一个 word 文件中的 panel2 中的所有这些项目。我尝试编写以下代码,但它不起作用。

private void button3_Click(object sender, EventArgs e)
{
    System.IO.File.WriteAllText(@"C:\users\dell\desktop\temp.docx",panel2.select);
}
4

1 回答 1

1

The .docx file is not a simple text file you can write to with File.WriteAllText. It is a very complex format (in fact it is a .zip file containing lots of xml files describing the structure and data of the document). Take a look at this question here: Generate Word document from c#

And also panel2.select won't do the job. You need to call textBox1.Text property in order to get the text from a TextBox. You will need to do that for everyone of them.

于 2013-03-18T07:02:01.643 回答