如何利用C#从WORD中读取内容并存入数据库
前提: 导入COM库:Microsoft word 11。
0 Object Library。 引用里面就增加了: 打开文档: object oMissing = System。
Reflection。Missing。
Value; Word。_Application oWord; Word。
_Document oDoc; oWord = new Word。Application(); oWord。
Visible = true; object fileName = @"E: c"; oDoc = oWord。Documents。
Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); 导入模板 object oMissing = System。 Reflection。
Missing。Value; Word。
_Application oWord; Word。_Document oDoc; oWord = new Word。
Application(); oWord。Visible = true; object fileName = @"E: c"; oDoc = oWord。
Documents。Add(ref fileName, ref oMissing, ref oMissing, ref oMissing);。
如何将Word文档导入或导出access数据库
导入:打开ACCESS——文件——获取外部数据——导入——在打开的对话框里选择你要导入的文档。
导入:打开ACCESS——在“表”对象的空白处点鼠标右键——导入——在打开的对话框里选择你要导入的文档。
导出:打开ACCESS——在“表”对象里选择想要导出的表点右键——导出——在打开的对话框里选择存放的盘和名字——保存。
导出:按上面导出方法导出,只是在保存的类型时选.txt格式,最后你打开导出的txt文本,将里面的内容复制到word里,应该可以成功的。你可以参照http://wenwen.soso.com/z/q128031057.htm
asp.net中word导入数据库问题
将Excel文件数据库导入SQL Server的三种方案//方案一: 通过OleDB方式获取Excel文件的数据,然后通过DataSet中转到SQL Server openFileDialog = new OpenFileDialog();openFileDialog.Filter = "Excel files(*.xls)|*.xls"; if(openFileDialog.ShowDialog()==DialogResult.OK){ FileInfo fileInfo = new FileInfo(openFileDialog.FileName); string filePath = fileInfo.FullName; string connExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=Excel 8.0"; try { OleDbConnection oleDbConnection = new OleDbConnection(connExcel); oleDbConnection.Open(); //获取excel表 DataTable dataTable = oleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); //获取sheet名,其中[0][1]。
[N]: 按名称排列的表单元素 string tableName = dataTable.Rows[0][2].ToString().Trim(); tableName = "[" + tableName.Replace("'","") + "]"; //利用SQL语句从Excel文件里获取数据 //string query = "SELECT classDate,classPlace,classTeacher,classTitle,classID FROM " + tableName; string query = "SELECT 日期,开课城市,讲师,课程名称,持续时间 FROM " + tableName; dataSet = new DataSet(); //OleDbCommand oleCommand = new OleDbCommand(query, oleDbConnection); //OleDbDataAdapter oleAdapter = new OleDbDataAdapter(oleCommand); OleDbDataAdapter oleAdapter = new OleDbDataAdapter(query,connExcel); oleAdapter.Fill(dataSet,"gch_Class_Info"); //dataGrid1.DataSource = dataSet; //dataGrid1.DataMember = tableName; dataGrid1.SetDataBinding(dataSet,"gch_Class_Info"); //从excel文件获得数据后,插入记录到SQL Server的数据表 DataTable dataTable1 = new DataTable(); SqlDataAdapter sqlDA1 = new SqlDataAdapter(@"SELECT classID, classDate,classPlace, classTeacher, classTitle, durativeDate FROM gch_Class_Info",sqlConnection1); SqlCommandBuilder sqlCB1 = new SqlCommandBuilder(sqlDA1); sqlDA1.Fill(dataTable1); foreach(DataRow dataRow in dataSet.Tables["gch_Class_Info"].Rows) { DataRow dataRow1 = dataTable1.NewRow(); dataRow1["classDate"] = dataRow["日期"]; dataRow1["classPlace"] = dataRow["开课城市"]; dataRow1["classTeacher"] = dataRow["讲师"]; dataRow1["classTitle"] = dataRow["课程名称"]; dataRow1["durativeDate"] = dataRow["持续时间"]; dataTable1.Rows.Add(dataRow1); } Console.WriteLine("新插入 " + dataTable1.Rows.Count.ToString() + " 条记录"); sqlDA1.Update(dataTable1); oleDbConnection.Close(); } catch(Exception ex) { Console.WriteLine(ex.ToString()); }} //方案二: 直接通过SQL语句执行SQL Server的功能函数将Excel文件转换到SQL Server数据库 OpenFileDialog openFileDialog = new OpenFileDialog();openFileDialog.Filter = "Excel files(*.xls)|*.xls"; SqlConnection sqlConnection1 = null; if(openFileDialog.ShowDialog()==DialogResult.OK){ string filePath = openFileDialog.FileName; sqlConnection1 = new SqlConnection(); sqlConnection1.ConnectionString = "server=(local);integrated security=SSPI;initial catalog=Library"; //import excel into SQL Server 2000 /*string importSQL = "SELECT * into live41 FROM OpenDataSource" + "('Microsoft.Jet.OLEDB.4.0','Data Source=" + "\"" + "E:\\022n.xls" + "\"" + "; User ID=;Password=; Extended properties=Excel 5.0')。[Sheet1$]";*/ //export SQL Server 2000 into excel string exportSQL = @"EXEC master..xp_cmdshell'bcp Library.dbo.live41 out " + filePath + "-c -q -S" + "\"" + "\"" + " -U" + "\"" + "\"" + " -P" + "\"" + "\"" + "\'"; try { sqlConnection1.Open(); //SqlCommand sqlCommand1 = new SqlCommand(); //sqlCommand1.Connection = sqlConnection1; //sqlCommand1.CommandText = importSQL; //sqlCommand1.ExecuteNonQuery(); //MessageBox.Show("import finish!"); SqlCommand sqlCommand2 = new SqlCommand(); sqlCommand2.Connection = sqlConnection1; sqlCommand2.CommandText = exportSQL; sqlCommand2.ExecuteNonQuery(); MessageBox.Show("export finish!"); } catch(Exception ex) { MessageBox.Show(ex.ToString()); }} if(sqlConnection1!=null){ sqlConnection1.Close(); sqlConnection1 = null;} //方案三: 通过到入Excel的VBA dll,通过VBA接口获取Excel数据到DataSet OpenFileDialog openFile = new OpenFileDialog();openFile.Filter = "Excel files(*.xls)|*.xls"; ExcelIO excelio = new ExcelIO(); if(openFile.ShowDialog()==DialogResult.OK){ if(excelio!=null) excelio.Close(); excelio = new ExcelIO(openFile.FileName); object[,] range = excelio.GetRange(); excelio.Close(); DataSet 。
如何实现WORD文档自动导入网站数据库
如何实现WORD文档自动导入网站数据库在Word中打开网页并将网页存为Word文档。
1,打开Word2003,单击菜单栏中的“文件”→“打开”对话框;2,在“文件名”编辑框中手动输入网页地址,并单击“打开”按钮;3,Word2003开始连接Web服务器,用户可以在Word窗口中看到目标网页内容;4,并且可以进行编辑、复制、删除和保存等操作,如图所示;提示:如果网页内容较多且有大量图片,则Word在打开网页时会出现“Word内存不足,修改之后无法撤销操作”,这个提示不会影响复制网页内容。5,选中需要复制的内容,并执行复制操作。
6,然后新建一个Word文档,将复制的内容粘贴到新的Word文档中,保存即可。
在线考试系统如何添加试题
不同家的在线考试系统添加试题的方法也都不一样,所以只能举例我用过的优考试了 操作方法如下: 一.手动添加试题 登录系统后,选择左侧题库管理并点击【新增试题】按钮即可进行手动输入试题。
进入手动添加试题界面时,先选择题型,再输入题目内容,如选择题题干和选项、问答题题干和参考答案等。 同时,还可以自定义分数、设置正确答案、解析、标签等。
二. 批量导入试题(重点推荐) 首先,选择题库管理的【导入试题】按钮; 要批量导入试题,需要下载word或excel模板; 下载模板后,按照模板编辑试题,点击“选择文件并上传”,即可把试题批量导入到试题中。 。
转载请注明出处51数据库 » word试题导入数据库