表结构设计:
MINGE_CODE_TBL
MC_TYPE INT
MC_FLAG CHAR(1)
MG_CD INT ------------ 外键
|
MG_CD_TBL |
MG_CD INT -----------------
MC1 INT
MC2 INT程序的主要流程:
1. 创建数据库、表
2. 解析WORD文件,将WORD表格中的数据,插入到数据库对应的表中
3. 读取数据库,显示数据。
程序UI设计:
1. 创建一个功能菜单名,并添加一个菜单选项名为(SP_1)。
2. 在SP_1菜单选项中,创建3个子选项(SP_1_A 创建MINGE_CODE_TBL)
(SP_1_B 解析WORD文件)
(SP_1_C 查看MINGE_CODE_TBL)
3. 点击SP_1_A 时,用SQL语句创建一个名为MINGE_CODE_TBL的表,如表已经存在,弹出提示让用户选择(是,否)重新创建,根据用户的选择,作出相应的操作(是,删除原表,再创建新表。否,返回不进行任何操作)
4. 点击SP_1_B时,弹出一个新的窗体,窗体UI显示如下:
5. 点击SP_1_C时,弹出一个新的窗体,用于显示数据,具体怎么显示,自由发挥。读取WORD表格 范例:public void readWordFile()
{
object oFileName = @"..\Files\Employees0.doc";
object oReadOnly = true;
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord = new
Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Open(ref oFileName, ref
oMissing, ref oReadOnly, 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); for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++)
{
Microsoft.Office.Interop.Word.Table nowTable = oDoc.Tables[tablePos];
string tableMessage = string.Format("第{0}/{1}个表:\n", tablePos, oDoc.Tables.Count); for (int rowPos = 1; rowPos <= nowTable.Rows.Count; rowPos++)
{
for (int columPos = 1; columPos <= nowTable.Columns.Count; columPos++)
{
tableMessage += nowTable.Cell(rowPos, columPos).Range.Text;
tableMessage += tableMessage.Remove(tableMessage.Length - 2, 2);
tableMessage += "\t";
}
tableMessage += "\n";
}
string msgTable = tableMessage;
}
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Marshal.ReleaseComObject(oDoc);
Marshal.FinalReleaseComObject(oWord);
oWord = null;
}1. 开始之前,请先加入参考MicroSoft Word 11.0 Object Library:
"参考"右键 ------> 加入参考 --------> "加入参考"对话框选择 "COM" 页 --------> 在列表中找到MicroSoft Word 11.0 Object Library 双击选取后确定,会发现参考中多出来两项:VBIDE和Word。/p>
2. 请添加using:
using Word;
3. 读取Word中的表格
private void btnIn_Click(object sender, System.EventArgs e)
{
try
{
object fileName = "E:\\BB.doc";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
Word.ApplicationClass oWordApp = new Word.ApplicationClass(); //开启应用程序WINWORD.EXE
//打开要操作的Word文檔
Word.Document oWordDoc = oWordApp.Documents.Open(ref fileName, ref missing,ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible,ref missing,ref missing,ref missing,ref missing);
oWordDoc.Activate();
//int i = oWordDoc.Tables.Count; //文文件中表格的个数
Word.Table nowTable = oWordDoc.Tables[1]; //文文件中第一个表格
//读取表格内容
string strProjName = nowTable.Cell(2, 2).Range.Text.ToString();
string strAssignEmployeeName = nowTable.Cell(3, 2).Range.Text.ToString();
string strAssignDate = nowTable.Cell(3, 4).Range.Text.ToString();
string strPreFinishDate = nowTable.Cell(4, 2).Range.Text.ToString();
string strChargeEmployeeName = nowTable.Cell(5, 2).Range.Text.ToString();
string strType = nowTable.Cell(8, 1).Range.Text.ToString();
string strDesc = nowTable.Cell(8, 2).Range.Text.ToString();
string strRem = nowTable.Cell(8, 3).Range.Text.ToString();
MINGE_CODE_TBL
MC_TYPE INT
MC_FLAG CHAR(1)
MG_CD INT ------------ 外键
|
MG_CD_TBL |
MG_CD INT -----------------
MC1 INT
MC2 INT程序的主要流程:
1. 创建数据库、表
2. 解析WORD文件,将WORD表格中的数据,插入到数据库对应的表中
3. 读取数据库,显示数据。
程序UI设计:
1. 创建一个功能菜单名,并添加一个菜单选项名为(SP_1)。
2. 在SP_1菜单选项中,创建3个子选项(SP_1_A 创建MINGE_CODE_TBL)
(SP_1_B 解析WORD文件)
(SP_1_C 查看MINGE_CODE_TBL)
3. 点击SP_1_A 时,用SQL语句创建一个名为MINGE_CODE_TBL的表,如表已经存在,弹出提示让用户选择(是,否)重新创建,根据用户的选择,作出相应的操作(是,删除原表,再创建新表。否,返回不进行任何操作)
4. 点击SP_1_B时,弹出一个新的窗体,窗体UI显示如下:
5. 点击SP_1_C时,弹出一个新的窗体,用于显示数据,具体怎么显示,自由发挥。读取WORD表格 范例:public void readWordFile()
{
object oFileName = @"..\Files\Employees0.doc";
object oReadOnly = true;
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord = new
Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Open(ref oFileName, ref
oMissing, ref oReadOnly, 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); for (int tablePos = 1; tablePos <= oDoc.Tables.Count; tablePos++)
{
Microsoft.Office.Interop.Word.Table nowTable = oDoc.Tables[tablePos];
string tableMessage = string.Format("第{0}/{1}个表:\n", tablePos, oDoc.Tables.Count); for (int rowPos = 1; rowPos <= nowTable.Rows.Count; rowPos++)
{
for (int columPos = 1; columPos <= nowTable.Columns.Count; columPos++)
{
tableMessage += nowTable.Cell(rowPos, columPos).Range.Text;
tableMessage += tableMessage.Remove(tableMessage.Length - 2, 2);
tableMessage += "\t";
}
tableMessage += "\n";
}
string msgTable = tableMessage;
}
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Marshal.ReleaseComObject(oDoc);
Marshal.FinalReleaseComObject(oWord);
oWord = null;
}1. 开始之前,请先加入参考MicroSoft Word 11.0 Object Library:
"参考"右键 ------> 加入参考 --------> "加入参考"对话框选择 "COM" 页 --------> 在列表中找到MicroSoft Word 11.0 Object Library 双击选取后确定,会发现参考中多出来两项:VBIDE和Word。/p>
2. 请添加using:
using Word;
3. 读取Word中的表格
private void btnIn_Click(object sender, System.EventArgs e)
{
try
{
object fileName = "E:\\BB.doc";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
Word.ApplicationClass oWordApp = new Word.ApplicationClass(); //开启应用程序WINWORD.EXE
//打开要操作的Word文檔
Word.Document oWordDoc = oWordApp.Documents.Open(ref fileName, ref missing,ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible,ref missing,ref missing,ref missing,ref missing);
oWordDoc.Activate();
//int i = oWordDoc.Tables.Count; //文文件中表格的个数
Word.Table nowTable = oWordDoc.Tables[1]; //文文件中第一个表格
//读取表格内容
string strProjName = nowTable.Cell(2, 2).Range.Text.ToString();
string strAssignEmployeeName = nowTable.Cell(3, 2).Range.Text.ToString();
string strAssignDate = nowTable.Cell(3, 4).Range.Text.ToString();
string strPreFinishDate = nowTable.Cell(4, 2).Range.Text.ToString();
string strChargeEmployeeName = nowTable.Cell(5, 2).Range.Text.ToString();
string strType = nowTable.Cell(8, 1).Range.Text.ToString();
string strDesc = nowTable.Cell(8, 2).Range.Text.ToString();
string strRem = nowTable.Cell(8, 3).Range.Text.ToString();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货