返回首页

您好

任何一个可以帮助我的代码

在DataGridView导出数据到Word文件..
我开发一个Windows应用程序。

我使用这个词的MS Office 2007,操作系统是Windows 7中,
和VS版本是微软的Visual Studio 2008 ...
调试在IS的x86

提前感谢
期待帮助...

回答

评论会员:CodingLover 时间:2012/02/06
阅读下面的文章。

评论会员:Ragi戈皮 时间:2012/02/06
private void button3_Click(object sender, EventArgs e)

        {

            Excel.Application xlApp;

            Excel.Workbook xlWorkBook;

            Excel.Worksheet xlWorkSheet;

            object misValue = System.Reflection.Missing.Value;

 

            xlApp = new Excel.ApplicationClass();

            xlWorkBook = xlApp.Workbooks.Add(misValue);

            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            int i = 0;

            int j = 0;

 

            for (i = 0; i <= dgv1.RowCount - 1; i++)

            {

                for (j = 0; j <= dgv1.ColumnCount - 1; j++)

                {

                    DataGridViewCell cell = dgv1[j, i];

                    xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;

                }

            }

 

            xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

            xlWorkBook.Close(true, misValue, misValue);

            xlApp.Quit();

 

            releaseObject(xlWorkSheet);

            releaseObject(xlWorkBook);

            releaseObject(xlApp);

 

            MessageBox.Show("Excel file created , you can find the file c:\\csharp.net-informations.xls");

       

        }
评论会员:CodingLover 时间:2012/02/06
{C} | Ragi戈皮
评论会员:游客 时间:2012/02/06
您好,这是很容易,当您按一下按钮出口,火:GridView1.MasterTableView.ExportToWord;e.g:codeprelang="cs"spanclass="code-keyword"protected/spanspanclass="code-keyword"void/spanbtnExport_Click(spanclass="code-keyword"object/spansender,EventArgse){ gvPaidtoSNA.ExportSettings.IgnorePaging=spanclass="code-keyword"true/span;gvPaidtoSNA.ExportSettings.OpenInNewWindow=spanclass="code-keyword"true/span;gvPaidtoSNA.MasterTableView.ExportToWord; }/pre/code
costavo
评论会员:游客 时间:2012/02/06
可以创建会议,并采取在每一页上的部份价值和定义的角色ID,如果一个用户有认证,然后他可以打开THA页,其他明智的,他可以​​不OPE页面,进一步是一些代码与这段代码的帮助下,你可以解决你的问题。{体C3}有作用的IDwhic,您可以定义您的网页上:。|