📄 dbtoword.cs
字号:
paragraph2.Range.InsertParagraphAfter();
obj4 = document.Bookmarks[&obj3].Range;
Paragraph paragraph3 = document.Content.Paragraphs.Add(ref obj4);
paragraph3.Range.Text = "";
paragraph3.Range.Font.Bold = 0;
paragraph3.Range.Font.Name = "宋体";
paragraph3.Range.Font.Size = 9f;
paragraph3.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
paragraph3.Format.SpaceBefore = 1f;
paragraph3.Format.SpaceAfter = 1f;
paragraph3.Range.InsertParagraphAfter();
Range range = document.Bookmarks[&obj3].Range;
Table table = document.Tables.Add(range, num3 + 1, 10, ref template, ref template);
table.Range.Font.Name = "宋体";
table.Range.Font.Size = 9f;
table.Borders.Enable = 1;
table.Rows.Height = 10f;
table.AllowAutoFit = true;
table.Cell(1, 1).Range.Text = "序号";
table.Cell(1, 2).Range.Text = "列名";
table.Cell(1, 3).Range.Text = "数据类型";
table.Cell(1, 4).Range.Text = "长度";
table.Cell(1, 5).Range.Text = "小数位";
table.Cell(1, 6).Range.Text = "标识";
table.Cell(1, 7).Range.Text = "主键";
table.Cell(1, 8).Range.Text = "允许空";
table.Cell(1, 9).Range.Text = "默认值";
table.Cell(1, 10).Range.Text = "说明";
table.Columns[1].Width = 33f;
table.Columns[3].Width = 60f;
table.Columns[4].Width = 33f;
table.Columns[5].Width = 43f;
table.Columns[6].Width = 33f;
table.Columns[7].Width = 33f;
table.Columns[8].Width = 43f;
for (int j = 0; j < num3; j++)
{
ColumnInfo info = columnInfoList[j];
string colorder = info.Colorder;
string columnName = info.ColumnName;
string typeName = info.TypeName;
string length = info.Length;
string scale = info.Scale;
string str9 = (info.IsIdentity.ToString().ToLower() == "true") ? "是" : "";
string str10 = (info.IsPK.ToString().ToLower() == "true") ? "是" : "";
string str11 = (info.cisNull.ToString().ToLower() == "true") ? "是" : "否";
string str12 = info.DefaultVal.ToString();
string str13 = info.DeText.ToString();
if (length.Trim() == "-1")
{
length = "MAX";
}
table.Cell(j + 2, 1).Range.Text = colorder;
table.Cell(j + 2, 2).Range.Text = columnName;
table.Cell(j + 2, 3).Range.Text = typeName;
table.Cell(j + 2, 4).Range.Text = length;
table.Cell(j + 2, 5).Range.Text = scale;
table.Cell(j + 2, 6).Range.Text = str9;
table.Cell(j + 2, 7).Range.Text = str10;
table.Cell(j + 2, 8).Range.Text = str11;
table.Cell(j + 2, 9).Range.Text = str12;
table.Cell(j + 2, 10).Range.Text = str13;
}
table.Rows[1].Range.Font.Bold = 1;
table.Rows[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
table.Rows.First.Shading.Texture = WdTextureIndex.wdTexture25Percent;
}
this.SetprogressBar1Val(i + 1);
this.SetlblStatuText((i + 1).ToString());
}
application.Visible = true;
document.Activate();
this.SetBtnEnable();
MessageBox.Show("文档生成成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
MessageBox.Show("文档生成失败!(" + exception.Message + ")。\r\n请关闭重试。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void ThreadWork1()
{
try
{
this.SetBtnDisable();
string text = "数据库名:" + this.dbname;
int count = this.listTable2.Items.Count;
this.SetprogressBar1Max(count);
this.SetprogressBar1Val(1);
this.SetlblStatuText("0");
object template = Missing.Value;
Document document = this.WordApp.Documents.Add(ref template, ref template, ref template, ref template);
this.WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
this.WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
this.WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[动软自动生成器www.maticsoft.com]");
this.WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
this.WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;
this.WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
this.WordApp.Selection.Font.Bold = 0x98967e;
this.WordApp.Selection.Font.Size = 12f;
this.WordApp.Selection.TypeText(text);
for (int i = 0; i < count; i++)
{
string tableName = this.listTable2.Items[i].ToString();
object missing = System.Type.Missing;
object length = text.Trim().Length;
Range range = document.Range(ref length, ref length);
this.WordApp.Selection.Tables.Add(range, 2, 10, ref template, ref template);
object type = 11;
range.InsertBreak(ref type);
range.InsertBreak(ref type);
range.InsertBefore("表名:" + tableName);
Table table = document.Tables[1];
table.Borders.Enable = 1;
table.AllowAutoFit = true;
table.Rows.Height = 15f;
Range range2 = table.Rows[1].Range;
range2.Font.Size = 9f;
range2.Font.Name = "宋体";
range2.Font.Bold = 1;
table.Cell(1, 1).Range.Text = "序号";
table.Cell(1, 2).Range.Text = "列名";
table.Cell(1, 3).Range.Text = "数据类型";
table.Cell(1, 4).Range.Text = "长度";
table.Cell(1, 5).Range.Text = "小数位";
table.Cell(1, 6).Range.Text = "标识";
table.Cell(1, 7).Range.Text = "主键";
table.Cell(1, 8).Range.Text = "允许空";
table.Cell(1, 9).Range.Text = "默认值";
table.Cell(1, 10).Range.Text = "说明";
table.Columns[1].Width = 33f;
table.Columns[3].Width = 60f;
table.Columns[4].Width = 33f;
table.Columns[5].Width = 43f;
table.Columns[6].Width = 33f;
table.Columns[7].Width = 33f;
table.Columns[8].Width = 43f;
List<ColumnInfo> columnInfoList = this.dbobj.GetColumnInfoList(this.dbname, tableName);
int row = 2;
if ((columnInfoList != null) && (columnInfoList.Count > 0))
{
foreach (ColumnInfo info in columnInfoList)
{
string colorder = info.Colorder;
string columnName = info.ColumnName;
string typeName = info.TypeName;
string str6 = info.Length;
string scale = info.Scale;
string str8 = (info.IsIdentity.ToString().ToLower() == "true") ? "是" : "";
string str9 = (info.IsPK.ToString().ToLower() == "true") ? "是" : "";
string str10 = (info.cisNull.ToString().ToLower() == "true") ? "是" : "否";
string str11 = info.DefaultVal.ToString();
string str12 = info.DeText.ToString();
if (str6.Trim() == "-1")
{
str6 = "MAX";
}
object beforeRow = System.Type.Missing;
table.Rows.Add(ref beforeRow);
table.Rows[row].Range.Select();
Range range3 = table.Rows[row].Range;
range3.Font.Size = 9f;
range3.Font.Name = "宋体";
range3.Font.Bold = 0;
range3.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
table.Cell(row, 1).Range.Text = colorder;
table.Cell(row, 2).Range.Text = columnName;
table.Cell(row, 3).Range.Text = typeName;
table.Cell(row, 4).Range.Text = str6;
table.Cell(row, 5).Range.Text = scale;
table.Cell(row, 6).Range.Text = str8;
table.Cell(row, 7).Range.Text = str9;
table.Cell(row, 8).Range.Text = str10;
table.Cell(row, 9).Range.Text = str11;
table.Cell(row, 10).Range.Text = str12;
row++;
}
}
this.SetprogressBar1Val(i + 1);
this.SetlblStatuText((i + 1).ToString());
table.Rows.First.Shading.Texture = WdTextureIndex.wdTexture25Percent;
}
this.WordApp.Visible = true;
document.Activate();
this.SetBtnEnable();
MessageBox.Show("文档生成成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
MessageBox.Show("文档生成失败!(" + exception.Message + ")。\r\n请关闭重试。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void ThreadWorkLoad()
{
string dbName = "master";
string dbType = this.dbobj.DbType;
if (dbType != null)
{
if (!(dbType == "SQL2000") && !(dbType == "SQL2005"))
{
if ((dbType == "Oracle") || (dbType == "OleDb"))
{
dbName = this.dbset.DbName;
}
else if (dbType == "MySQL")
{
dbName = "mysql";
}
}
else
{
dbName = "master";
}
}
if ((this.dbset.DbName == "") || (this.dbset.DbName == dbName))
{
List<string> dBList = this.dbobj.GetDBList();
if ((dBList != null) && (dBList.Count > 0))
{
foreach (string str2 in dBList)
{
this.cmbDB.Items.Add(str2);
}
}
}
else
{
this.cmbDB.Items.Add(this.dbset.DbName);
}
if (this.cmbDB.Items.Count > 0)
{
this.cmbDB.SelectedIndex = 0;
}
else
{
List<string> tables = this.dbobj.GetTables("");
this.listTable1.Items.Clear();
this.listTable2.Items.Clear();
if (tables.Count > 0)
{
this.SetprogressBar1Max(tables.Count);
this.SetprogressBar1Val(1);
this.SetlblStatuText("");
int val = 1;
foreach (string str3 in tables)
{
this.listTable1.Items.Add(str3);
this.SetprogressBar1Val(val);
this.SetlblStatuText(str3);
}
}
}
}
private delegate void SetBtnDisableCallback();
private delegate void SetBtnEnableCallback();
private delegate void SetlblStatuCallback(string text);
private delegate void SetProBar1MaxCallback(int val);
private delegate void SetProBar1ValCallback(int val);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -