全部讨论2 条
-
hyhtx*** 购买咨询为何登录后出现下列问题?请高手指点。
其他 2 条回复
-
wxc50***你调试下吧 ,你报的错是空指针异常 AO1表 没有,你看下你的数据库连接的有没有问题,或数据库
-
acmlu***您好,我刚也遇到这个问题,我已经解决了,将Microsoft.Office.Interop.Word.Tables.Items[index]改成Microsoft.Office.Interop.Word.Tables[index]就可以了。如果不能解决联系我,QQ:***
-
-
chaoj*** 其他using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.IO; namespace WindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ExportToWord(); } public void GetTempFileName() { } public void ExportToWord() { string c; SqlConnection myConn = new SqlConnection(connectionString); myConn.Open(); SqlDataAdapter sda = new SqlDataAdapter("select * from Theme", myConn); DataSet ds = new DataSet("ds"); sda.FillSchema(ds, SchemaType.Mapped, "Theme"); sda = new SqlDataAdapter("select * from Theme", myConn); sda.FillSchema(ds, SchemaType.Mapped, "Theme"); sda.Fill(ds, "Theme"); if (ds.Tables.Count != 0) { string tempFileName = null; object filename = null; object tableBehavior = Microsoft.Office.Interop.Word.WdDefaultTableBehavior.wdWord8TableBehavior; object autoFitBehavior = Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitFixed; object unit = Microsoft.Office.Interop.Word.WdUnits.wdStory; object extend = System.Reflection.Missing.Value; object breakType = (int)Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakNextPage; object count = 1; object character = Microsoft.Office.Interop.Word.WdUnits.wdCharacter; object Nothing = System.Reflection.Missing.Value; try { //tempFileName = GetTempFileName(); //生成.doc完整路径名 filename = "C:\\Program Files" + "asd" + ".doc"; //创建一个WORD文件,文件名用系统时间生成精确到毫秒 Microsoft.Office.Interop.Word.Application myWord = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document myDoc = new Microsoft.Office.Interop.Word.DocumentClass(); // myDoc = myWord.Documents.Add(); myDoc.Activate(); //向把dataset中的表插入到word文件中 for (int totalTable = 0; totalTable < ds.Tables.Count; totalTable++) { myWord.Application.Selection.TypeText(ds.Tables[totalTable].TableName + "表的数据如下"); myWord.Application.Selection.TypeParagraph(); Microsoft.Office.Interop.Word.Range para = myWord.Application.Selection.Range; myDoc.Tables.Add(para, ds.Tables[totalTable].Rows.Count + 1, ds.Tables[totalTable].Columns.Count, ref tableBehavior, ref autoFitBehavior); for (int column = 0; column < ds.Tables[totalTable].Columns.Count; column++) { myDoc.Tables.Item(totalTable + 1).Cell(1, column+1).Range.InsertBefore(ds.Tables[0].Columns[column].ColumnName.Trim()); } for (int row = 0; row < ds.Tables[totalTable].Rows.Count; row++) { for (int column = 0; column < ds.Tables[totalTable].Columns.Count; column++) { myDoc.Tables.Item(totalTable + 1).Cell(row + 2, column + 1).Range.InsertBefore(ds.Tables[totalTable].Rows[row][column].ToString().Trim()); } } myWord.Application.Selection.EndKey(ref unit, ref extend); myWord.Application.Selection.TypeParagraph();//原程序此话写了两次 myWord.Application.Selection.InsertBreak(ref breakType); } myWord.Application.Selection.TypeBackspace(); myWord.Application.Selection.Delete(ref character, ref count); myWord.Application.Selection.HomeKey(ref unit, ref extend); //保存word文件到指定的目录下 try { //myDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing); myWord.Visible = true; } catch { System.Windows.Forms.MessageBox.Show("系统找不到指定目录下的文件:" + "C:\\Program Files" + tempFileName + ".doc"); return; } //让生成的word文件可见 myWord.Visible = true; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("向word文件中写入数据出错:" + ex.Message); } } else { System.Windows.Forms.MessageBox.Show("没有数据"); } } } } 问题: 第80行:错误提示说:错误 1 “Microsoft.Office.Interop.Word.Tables”并不包含“Item”的定义 E:\rexian\WindowsApplication2\WindowsApplication2\Form1.cs 80 42 WindowsApplication2 该怎么办?
问问商家
看起来你想找人定制开发。留言要等商家看到才有回复,填一份定制需求单,商家和平台商务会直接联系你,比在留言里来回问快。
填写定制需求