如何读取WORD文档内容 并存入数据库 图为word内容。请大神给个读取方法。本人初学。。啥都不懂自己尝试的老是报错 获取不到内容,oDoc.Content.Tables[1];oDoc.Tables.Count..;等语句怎么写都报错。。c# WORD 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要保存word,不用读取内容,就把word以数据流的方式存入二进制字段就行了,google “c# 数据库 图片”,道理和保存图片一样 3个部门 care_code,country,content,按此对应插入数据库,我百度了好多方法,但是我照写下来都会报错。至于 数据流 您说的用 FileStream么? 二进制字段等 因初学这些基本不大懂。(未真正去过软体公司,深入技术,原理等都未掌握,只会基础的。 ),能说的通俗易懂点么。虽然那如山回复你觉得很通俗的描述。对于菜鸟中的菜鸟很难理解哈。 3个部门 care_code,country,content,按此对应插入数据库,我百度了好多方法,但是我照写下来都会报错。至于 数据流 您说的用 FileStream么? 二进制字段等 因初学这些基本不大懂。(未真正去过软体公司,深入技术,原理等都未掌握,只会基础的。 ),能说的通俗易懂点么。虽然那如山回复你觉得很通俗的描述。对于菜鸟中的菜鸟很难理解哈。、3个部门。。====》 字段 我好早之前做一个将数据库中的数据导入word,也就是生成一个带表格的word文件大概代码: /// <summary> /// 新建表格 /// </summary> /// <param name="doc"></param> /// <param name="oral"></param> private static void NewTable(Document doc,Oral_subject oral) { if(doc != null) { object defaultV = System.Reflection.Missing.Value; object what = WdUnits.wdLine; object count = 1; if (doc.Tables.Count == 0) { object bName="Items"; doc.Books.get_Item(ref bName).Select(); } else { doc.Tables[doc.Tables.Count].Select(); //what = WdUnits.wdCharacter; //doc.Application.Selection.MoveRight(ref what, ref count, ref defaultV); //what = WdUnits.wdLine; doc.Application.Selection.MoveDown(ref what, ref count, ref defaultV); } doc.Application.Selection.TypeParagraph(); doc.Application.Selection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceExactly; doc.Application.Selection.ParagraphFormat.LineSpacing = 17; doc.Application.Selection.Font.Size = 14; doc.Application.Selection.Font.Bold = 1; doc.Application.Selection.TypeText(items[doc.Tables.Count] + " " + OralLibraryManager.GetPartitionByPID(oral.Partition_ID).Partition_name); doc.Application.Selection.TypeParagraph(); doc.Application.Selection.Font.Bold = 0; doc.Application.Selection.Font.Size = 13; doc.Application.Selection.TypeText("说明:"); doc.Application.Selection.TypeParagraph(); doc.Application.Selection.TypeText(" 1、○项类别试题为必考题目;"); doc.Application.Selection.TypeParagraph(); doc.Application.Selection.TypeText(" 2、△项类别试题为选考题目;"); doc.Application.Selection.TypeParagraph(); doc.Application.Selection.TypeText(" 3、考官记录只需在试题类别○或△上打√或×来记录考生的答题情况。"); doc.Application.Selection.TypeParagraph(); Table tb = doc.Tables.Add(doc.Application.Selection.Range, 1, 3, ref defaultV, ref defaultV); //插入表格 tb.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle; tb.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle; tb.Rows[1].Cells[1].Range.Text = "考试题目"; //表头 tb.Rows[1].Cells[2].Range.Text = "类别"; tb.Rows[1].Cells[1].Range.Font.Size = 14; tb.Rows[1].Cells[2].Range.Font.Size = 14; tb.Rows[1].Cells[1].Range.Font.Bold = 0; tb.Rows[1].Cells[2].Range.Font.Bold = 0; tb.Rows[1].Cells[1].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceExactly; tb.Rows[1].Cells[1].Range.ParagraphFormat.LineSpacing = 17; tb.Rows[1].Cells[2].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceExactly; tb.Rows[1].Cells[2].Range.ParagraphFormat.LineSpacing = 17; tb.Rows[1].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; tb.Rows[1].Cells[2].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; tb.Columns[1].Width = 340; tb.Columns[2].Width = 40; tb.Columns[3].Width = 40; } } /// <summary> /// 插入总结 /// </summary> /// <param name="ht"></param> /// <param name="doc"></param> /// <param name="list"></param> private static void InsertStatistic(Hashtable ht, Document doc,List<Oral_subject> list) { if (doc != null) { object oMissing = System.Reflection.Missing.Value; object bName = "Statistic"; doc.Books.get_Item(ref bName).Select(); doc.Application.Selection.TypeParagraph(); Table tb = doc.Tables.Add(doc.Application.Selection.Range, 1, 3, ref oMissing, ref oMissing); //插入“总结”表 tb.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle; tb.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle; tb.Rows[1].Cells[1].Range.Text = "考试项目"; //表头 tb.Rows[1].Cells[2].Range.Text = "○数目"; tb.Rows[1].Cells[3].Range.Text = "△数目"; tb.Rows[1].Cells[1].Range.Font.Size = 14; tb.Rows[1].Cells[2].Range.Font.Size = 14; tb.Rows[1].Cells[3].Range.Font.Size = 14; tb.Rows[1].Cells[1].Range.Font.Bold = 1; tb.Rows[1].Cells[2].Range.Font.Bold = 1; tb.Rows[1].Cells[3].Range.Font.Bold = 1; tb.Rows[1].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; tb.Rows[1].Cells[2].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; tb.Rows[1].Cells[3].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; tb.Columns[1].Width = 300; tb.Columns[2].Width = 60; tb.Columns[3].Width = 60; // if (ht != null) //所有题目表 { object s = 1; Row row; foreach (DictionaryEntry de in ht) { int pos = int.Parse(de.Key.ToString()); int b = 0; int x = 0; GetTypeCount(ref b, ref x, doc.Tables[pos]); //Row row = tb.Rows.Add(ref oMissing); tb.Rows[1].Select(); doc.Application.Selection.InsertRowsBelow(ref s); row = tb.Rows[2]; row.Cells[1].Range.Text = items[pos - 1] + " " + de.Value.ToString(); row.Cells[2].Range.Text = b.ToString(); row.Cells[3].Range.Text = x.ToString(); row.Cells[1].Range.Font.Bold = 0; row.Cells[2].Range.Font.Bold = 0; row.Cells[3].Range.Font.Bold = 0; row.Cells[1].Range.Font.Size = 13; row.Cells[2].Range.Font.Size = 13; row.Cells[3].Range.Font.Size = 13; row.Cells[1].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5; row.Cells[2].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5; row.Cells[3].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5; } tb.Rows[tb.Rows.Count].Select(); doc.Application.Selection.InsertRowsBelow(ref s); row = tb.Rows[tb.Rows.Count]; int B = 0; int X = 0; foreach (Oral_subject oral in list) { if (oral.Osubject_type == 0) { B++; } else { X++; } } row.Cells[1].Range.Text = "合计数目"; row.Cells[2].Range.Text = B.ToString(); row.Cells[3].Range.Text = X.ToString(); row.Cells[1].Range.Font.Bold = 1; row.Cells[2].Range.Font.Bold = 0; row.Cells[3].Range.Font.Bold = 0; row.Cells[1].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5; row.Cells[2].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5; row.Cells[3].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5; } } }我就截取了其中两个设计到表格的方法 你凑合着看看吧 其余的太多 就不贴了 具体啥意思 我也搞忘记了 单签--》当前是要选中所有内容后再去做动作么?之前只是打开后 就直接去取他的table 数等。我去试式看。。我是一只小小小菜鸟。。想要飞呀飞,却飞不出这谜团。 http://www.189works.com/article-58086-1.html 这个比较简单的 http://www.189works.com/article-58086-1.html c# 开机自启动 我花了N个图,想让直线在最上面,怎么实现? 实现orm框架 中的 复杂查询问题 这个存储过程是错误的? 一个算法题 在制作安装程序时候,怎么自动安装MS SQL Server2000 C# 导出Excel文件 命令不可用。因为使用该应用程序的许可已经过期 最关键的问题 不使用ArrayList在C#如何使用动态数组 一条简单的SQL语句 求大虾们帮忙解决 调用控件的问题 请问下C#如何建立畸形文件夹?
至于 数据流 您说的用 FileStream么? 二进制字段等 因初学这些基本不大懂。(未真正去过软体公司,深入技术,原理等都未掌握,只会基础的。 ),能说的通俗易懂点么。虽然那如山回复你觉得很通俗的描述。对于菜鸟中的菜鸟很难理解哈。
至于 数据流 您说的用 FileStream么? 二进制字段等 因初学这些基本不大懂。(未真正去过软体公司,深入技术,原理等都未掌握,只会基础的。 ),能说的通俗易懂点么。虽然那如山回复你觉得很通俗的描述。对于菜鸟中的菜鸟很难理解哈。、
3个部门。。====》 字段
大概代码:
/// <summary>
/// 新建表格
/// </summary>
/// <param name="doc"></param>
/// <param name="oral"></param>
private static void NewTable(Document doc,Oral_subject oral)
{
if(doc != null)
{
object defaultV = System.Reflection.Missing.Value;
object what = WdUnits.wdLine;
object count = 1; if (doc.Tables.Count == 0)
{
object bName="Items";
doc.Books.get_Item(ref bName).Select();
}
else
{
doc.Tables[doc.Tables.Count].Select();
//what = WdUnits.wdCharacter;
//doc.Application.Selection.MoveRight(ref what, ref count, ref defaultV);
//what = WdUnits.wdLine;
doc.Application.Selection.MoveDown(ref what, ref count, ref defaultV);
}
doc.Application.Selection.TypeParagraph();
doc.Application.Selection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceExactly;
doc.Application.Selection.ParagraphFormat.LineSpacing = 17;
doc.Application.Selection.Font.Size = 14;
doc.Application.Selection.Font.Bold = 1;
doc.Application.Selection.TypeText(items[doc.Tables.Count] + " " + OralLibraryManager.GetPartitionByPID(oral.Partition_ID).Partition_name);
doc.Application.Selection.TypeParagraph();
doc.Application.Selection.Font.Bold = 0;
doc.Application.Selection.Font.Size = 13;
doc.Application.Selection.TypeText("说明:"); doc.Application.Selection.TypeParagraph();
doc.Application.Selection.TypeText(" 1、○项类别试题为必考题目;");
doc.Application.Selection.TypeParagraph();
doc.Application.Selection.TypeText(" 2、△项类别试题为选考题目;");
doc.Application.Selection.TypeParagraph();
doc.Application.Selection.TypeText(" 3、考官记录只需在试题类别○或△上打√或×来记录考生的答题情况。");
doc.Application.Selection.TypeParagraph(); Table tb = doc.Tables.Add(doc.Application.Selection.Range, 1, 3, ref defaultV, ref defaultV); //插入表格
tb.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
tb.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
tb.Rows[1].Cells[1].Range.Text = "考试题目"; //表头
tb.Rows[1].Cells[2].Range.Text = "类别";
tb.Rows[1].Cells[1].Range.Font.Size = 14;
tb.Rows[1].Cells[2].Range.Font.Size = 14;
tb.Rows[1].Cells[1].Range.Font.Bold = 0;
tb.Rows[1].Cells[2].Range.Font.Bold = 0;
tb.Rows[1].Cells[1].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceExactly;
tb.Rows[1].Cells[1].Range.ParagraphFormat.LineSpacing = 17;
tb.Rows[1].Cells[2].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceExactly;
tb.Rows[1].Cells[2].Range.ParagraphFormat.LineSpacing = 17; tb.Rows[1].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
tb.Rows[1].Cells[2].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; tb.Columns[1].Width = 340;
tb.Columns[2].Width = 40;
tb.Columns[3].Width = 40; }
} /// <summary>
/// 插入总结
/// </summary>
/// <param name="ht"></param>
/// <param name="doc"></param>
/// <param name="list"></param>
private static void InsertStatistic(Hashtable ht, Document doc,List<Oral_subject> list)
{
if (doc != null)
{
object oMissing = System.Reflection.Missing.Value;
object bName = "Statistic";
doc.Books.get_Item(ref bName).Select();
doc.Application.Selection.TypeParagraph(); Table tb = doc.Tables.Add(doc.Application.Selection.Range, 1, 3, ref oMissing, ref oMissing); //插入“总结”表
tb.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
tb.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle; tb.Rows[1].Cells[1].Range.Text = "考试项目"; //表头
tb.Rows[1].Cells[2].Range.Text = "○数目";
tb.Rows[1].Cells[3].Range.Text = "△数目"; tb.Rows[1].Cells[1].Range.Font.Size = 14;
tb.Rows[1].Cells[2].Range.Font.Size = 14;
tb.Rows[1].Cells[3].Range.Font.Size = 14; tb.Rows[1].Cells[1].Range.Font.Bold = 1;
tb.Rows[1].Cells[2].Range.Font.Bold = 1;
tb.Rows[1].Cells[3].Range.Font.Bold = 1; tb.Rows[1].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
tb.Rows[1].Cells[2].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
tb.Rows[1].Cells[3].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; tb.Columns[1].Width = 300;
tb.Columns[2].Width = 60;
tb.Columns[3].Width = 60; // if (ht != null) //所有题目表
{
object s = 1;
Row row;
foreach (DictionaryEntry de in ht)
{
int pos = int.Parse(de.Key.ToString());
int b = 0;
int x = 0; GetTypeCount(ref b, ref x, doc.Tables[pos]); //Row row = tb.Rows.Add(ref oMissing);
tb.Rows[1].Select();
doc.Application.Selection.InsertRowsBelow(ref s);
row = tb.Rows[2]; row.Cells[1].Range.Text = items[pos - 1] + " " + de.Value.ToString();
row.Cells[2].Range.Text = b.ToString();
row.Cells[3].Range.Text = x.ToString(); row.Cells[1].Range.Font.Bold = 0;
row.Cells[2].Range.Font.Bold = 0;
row.Cells[3].Range.Font.Bold = 0; row.Cells[1].Range.Font.Size = 13;
row.Cells[2].Range.Font.Size = 13;
row.Cells[3].Range.Font.Size = 13; row.Cells[1].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5;
row.Cells[2].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5;
row.Cells[3].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5;
}
tb.Rows[tb.Rows.Count].Select();
doc.Application.Selection.InsertRowsBelow(ref s);
row = tb.Rows[tb.Rows.Count];
int B = 0;
int X = 0; foreach (Oral_subject oral in list)
{
if (oral.Osubject_type == 0)
{
B++;
}
else
{
X++;
}
} row.Cells[1].Range.Text = "合计数目";
row.Cells[2].Range.Text = B.ToString();
row.Cells[3].Range.Text = X.ToString(); row.Cells[1].Range.Font.Bold = 1;
row.Cells[2].Range.Font.Bold = 0;
row.Cells[3].Range.Font.Bold = 0;
row.Cells[1].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5;
row.Cells[2].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5;
row.Cells[3].Range.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpace1pt5;
} }
}
我就截取了其中两个设计到表格的方法 你凑合着看看吧 其余的太多 就不贴了 具体啥意思 我也搞忘记了
我去试式看。。
我是一只小小小菜鸟。。想要飞呀飞,却飞不出这谜团。