标题:怎样才能把窗体内的Label和TextBox等文本区的内容导出一个word pdf html等格 ...
只看楼主
hanqiujun
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-9-14
结帖率:100%
已结贴  问题点数:20 回复次数:2 
怎样才能把窗体内的Label和TextBox等文本区的内容导出一个word pdf html等格式的文件?
如果窗体上有很多控件,比如做一个调查表,你填写完文本框后,我想将这个调查表导出生成word,word中的内容基本和窗体布局一样,这样应该如何编写呢?
搜索更多相关主题的帖子: TextBox Label pdf word 窗体 
2009-09-14 15:06
我爱编程1
Rank: 2
等 级:论坛游民
帖 子:4
专家分:20
注 册:2009-3-19
得分:20 

        private void button1_Click(object sender, System.EventArgs e)
        {//保存为EXCEL文件
            if(this.listView1.Items.Count<1)
                return;
            try
            {
                Excel.ApplicationClass MyExcel=new Excel.ApplicationClass();
                MyExcel.Visible=true;
                if(MyExcel==null)
                {
                    MessageBox.Show("EXCEL无法启动!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    return;
                }
                Excel.Workbooks MyWorkBooks = MyExcel.Workbooks;
                Excel.Workbook MyWorkBook = MyWorkBooks.Add(Missing.Value);
                Excel.Worksheet MyWorkSheet = (Excel.Worksheet)MyWorkBook.Worksheets[1];
                Excel.Range MyRange = MyWorkSheet.get_Range("A1","C1");
                object [] MyHeader = {"姓名","专业","毕业院校"};
                MyRange.Value2= MyHeader;
                if (this.listView1.Items.Count >0)
                {
                    MyRange =MyWorkSheet.get_Range("A2",Missing.Value);   
                    object [,] MyData = new Object[this.listView1.Items.Count,3];
                    foreach(ListViewItem lvi in this.listView1.Items)
                    {
                        MyData[lvi.Index,0] = lvi.Text;
                        MyData[lvi.Index,1] = lvi.SubItems[1].Text;
                        MyData[lvi.Index,2] = lvi.SubItems[2].Text;
                    }
                    MyRange = MyRange.get_Resize(this.listView1.Items.Count,3);
                    MyRange.Value2= MyData;
                    MyRange.EntireColumn.AutoFit();  
                }
                MyExcel= null;
            }
            catch(Exception Err)
            {
                MessageBox.Show("调用EXCEL程序时出现错误!"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }
 
        private void button2_Click(object sender, System.EventArgs e)
        {//填充表格数据内容
            int itemNumber=this.listView1.Items.Count;
            string[] subItem0={"王斌","计算机科学技术","武汉大学"};
            this.listView1.Items.Insert(itemNumber,    new ListViewItem(subItem0));
            string[] subItem1={"汪兰","财会电算化管理","西南财经大学"};
            this.listView1.Items.Insert(itemNumber,    new ListViewItem(subItem1));
            string[] subItem2={"汤波","计算机软件技术","上海交通大学"};
            this.listView1.Items.Insert(itemNumber,    new ListViewItem(subItem2));
            string[] subItem3={"罗成","计算机管理","重庆大学"};
            this.listView1.Items.Insert(itemNumber,    new ListViewItem(subItem3));
            string[] subItem4={"汤小敏","环境保护","西南师范大学"};
            this.listView1.Items.Insert(itemNumber,    new ListViewItem(subItem4));
            string[] subItem5={"刘功得","轻工机械装备","重庆市轻工业学校"};
            this.listView1.Items.Insert(itemNumber,    new ListViewItem(subItem5));            
        }
自己慢慢看啊,
2009-09-14 17:42
wyp68448
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2009-9-19
得分:0 
倒成offcie格式的文件比较简单,vs2005本身的库可以支持,因为都是微软出的软件嘛,都预留接口了,html更简单了,超文本标记语言(html)本身就是文本,按照格式要求利用IO接口输出就行了,但是PDF,Email等就麻烦一些,因为它们的编解码与加密方式不是微软制作的,而他本身也没有给微软的软件特意预留接口,必须引用他的控件,或一些第三方控件才可导入与导出!否则不是不行,而是很麻烦了!
2009-09-19 09:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-285696-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031622 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved