/// <summary> /// 到处Word /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { Database db = new Database(); var wordList = new List <WordModel>(); foreach (DataGridViewRow dgvr in gvDataTable.Rows) { var checkBoxCell = (DataGridViewCheckBoxCell)dgvr.Cells["Selected"]; var isChecked = Convert.ToBoolean(checkBoxCell.Value); if (isChecked) { var tableName = dgvr.Cells["TableName"].Value.ToString(); DataTable tbDt = db.GetDataTable(@"select col.name as 字段,t.name as 类型,col.max_length as 长度,case when col.is_nullable=0 then 'N' else 'Y' end as 是否为空,ep.value as 说明 from sys.objects obj inner join sys.columns col on obj.object_id=col.object_id left join sys.types t on t.user_type_id=col.user_type_id left join sys.extended_properties ep on ep.major_id=obj.object_id and ep.minor_id=col.column_id where obj.name=@0", tableName); wordList.Add(new WordModel() { TableDt = tbDt, TableName = tableName }); } } if (wordList.Count > 0) { WordHelper.ExportDataListToWord(wordList); } else { MessageBox.Show("没有选中表"); } }