屏幕裂开了,电脑内存怎么扩大扩大,福田哪里修手机比较好

假如我们需要在一个word文档的某个位置插入一张表格,而且要对这一张表格中的单元格做拆分合并,之类的。
先看下效果,先不管表格是否合理,总之就是要这样的统计文档,但是人数,班级数都是不确定的,也就是表格是根 据数据动态生成的,
这样我们就很难用之前的替换方式来实现,也就是要动态来创建表格。
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 班级成绩统计单
1、用单元格拆分的方式实现,也就是根据有多少班级,则增加多少行,针对于其中的学生信息再对单元格进行拆分。
/// &summary&
/// 数据实体类
/// &/summary&
public class Student
public string N//姓名
public int S//成绩
public string StuC//班级
public string L//班主任
/// &summary&
/// 动态创建table到word
/// &/summary&
protected void CreateTableToExcel()
Word.Application app = null;
Word.Document doc = null;
//构造数据
List&Student& datas = new List&Student&();
datas.Add(new Student{ Leader="小李", Name="张三", Score=498, StuClass="一班"});
datas.Add(new Student{ Leader="陈飞", Name="李四", Score=354, StuClass="二班"});
datas.Add(new Student{ Leader="陈飞", Name="小红", Score=502, StuClass="二班"});
datas.Add(new Student{ Leader="王林", Name="丁爽", Score=566, StuClass="三班"});
var cate = datas.GroupBy(s=&s.StuClass);
int rows = cate.Count()+1;//表格行数加1是为了标题栏
int cols = 5;//表格列数
object oMissing = System.Reflection.Missing.V
app = new Word.Application();//创建word应用程序
doc = app.Documents.Add();//添加一个word文档
//输出大标题加粗加大字号水平居中
app.Selection.Font.Bold = 700;
app.Selection.Font.Size = 16;
app.Selection.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphC
app.Selection.Text = "班级成绩统计单";
//换行添加表格
object line = Word.WdUnits.wdL
app.Selection.MoveDown(ref line, oMissing, oMissing);
app.Selection.TypeParagraph();//换行
Word.Range range = app.Selection.R
Word.Table table = app.Selection.Tables.Add(range, rows, cols, ref oMissing, ref oMissing);
//设置表格的字体大小粗细
table.Range.Font.Size = 10;
table.Range.Font.Bold=0;
//设置表格标题
int rowIndex = 1;
table.Cell(rowIndex, 1).Range.Text = "班级";
table.Cell(rowIndex, 2).Range.Text = "姓名";
table.Cell(rowIndex, 3).Range.Text = "成绩";
table.Cell(rowIndex, 4).Range.Text = "人数";
table.Cell(rowIndex, 5).Range.Text = "班主任";
//循环数据创建数据行
rowIndex++;
foreach (var i in cate)
table.Cell(rowIndex, 1).Range.Text = i.K//班级
table.Cell(rowIndex, 4).Range.Text = i.Count().ToString();//人数
table.Cell(rowIndex, 5).Range.Text = i.First().L//班主任
table.Cell(rowIndex,2).Split(i.Count(), 1);//分割名字单元格
table.Cell(rowIndex,3).Split(i.Count(), 1);//分割成绩单元格
//对表格中的班级、姓名,成绩单元格设置上下居中
table.Cell(rowIndex, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalC
table.Cell(rowIndex, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalC
table.Cell(rowIndex, 5).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalC
//构建姓名,成绩数据
foreach (var x in i)
table.Cell(rowIndex, 2).Range.Text = x.N
table.Cell(rowIndex, 3).Range.Text = x.Score.ToString();
rowIndex++;
//导出到文件
string newFile = DateTime.Now.ToString("yyyyMMddHHmmssss") + ".doc";
string physicNewFile = Server.MapPath(newFile);
doc.SaveAs(physicNewFile,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
catch(Exception ex)
if (doc != null)
doc.Close();//关闭文档
if (app != null)
app.Quit();//退出应用程序
&2、单元格合并的方式,即循环数据输出,然后对班级,人数,班主任列进行合并,但是合并的时候需要注意,假如某班级只有一个同学,也就是其实不需要合并的,
则必须排除在外,否则会出现&此命令无效&的异常,所以下面代码在合并的时候做了一个判断。
protected void CreateTableToExcel2()
Word.Application app = null;
Word.Document doc = null;
//构造数据
List&Student& datas = new List&Student&();
datas.Add(new Student { Leader = "小李", Name = "张三", Score = 498, StuClass = "一班" });
datas.Add(new Student { Leader = "陈飞", Name = "李四", Score = 354, StuClass = "二班" });
datas.Add(new Student { Leader = "陈飞", Name = "小红", Score = 502, StuClass = "二班" });
datas.Add(new Student { Leader = "王林", Name = "丁爽", Score = 566, StuClass = "三班" });
var cate = datas.GroupBy(s =& s.StuClass);
int rows = datas.Count + 1;
int cols = 5;//表格列数
object oMissing = System.Reflection.Missing.V
app = new Word.Application();//创建word应用程序
doc = app.Documents.Add();//添加一个word文档
//输出大标题加粗加大字号水平居中
app.Selection.Font.Bold = 700;
app.Selection.Font.Size = 16;
app.Selection.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphC
app.Selection.Text = "班级成绩统计单";
//换行添加表格
object line = Word.WdUnits.wdL
app.Selection.MoveDown(ref line, oMissing, oMissing);
app.Selection.TypeParagraph();//换行
Word.Range range = app.Selection.R
Word.Table table = app.Selection.Tables.Add(range, rows, cols, ref oMissing, ref oMissing);
//设置表格的字体大小粗细
table.Range.Font.Size = 10;
table.Range.Font.Bold = 0;
//设置表格标题
int rowIndex = 1;
table.Cell(rowIndex, 1).Range.Text = "班级";
table.Cell(rowIndex, 2).Range.Text = "姓名";
table.Cell(rowIndex, 3).Range.Text = "成绩";
table.Cell(rowIndex, 4).Range.Text = "人数";
table.Cell(rowIndex, 5).Range.Text = "班主任";
//循环数据创建数据行
rowIndex++;
foreach (var i in cate)
int moveCount = i.Count() - 1;//纵向合并行数
if (moveCount.ToString() != "0")
table.Cell(rowIndex, 1).Merge(table.Cell(rowIndex + moveCount, 1));//合并班级
table.Cell(rowIndex, 4).Merge(table.Cell(rowIndex + moveCount, 4));//合并人数
table.Cell(rowIndex, 5).Merge(table.Cell(rowIndex + moveCount, 5));//合并班主任
//写入合并的数据并垂直居中
table.Cell(rowIndex, 1).Range.Text = i.K
table.Cell(rowIndex, 4).Range.Text = i.Count().ToString();
table.Cell(rowIndex, 5).Range.Text = i.First().L
table.Cell(rowIndex, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalC
table.Cell(rowIndex, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalC
table.Cell(rowIndex, 5).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalC
//构建姓名,成绩数据
foreach (var x in i)
table.Cell(rowIndex, 2).Range.Text = x.N
table.Cell(rowIndex, 3).Range.Text = x.Score.ToString();
rowIndex++;
//导出到文件
string newFile = DateTime.Now.ToString("yyyyMMddHHmmssss") + ".doc";
string physicNewFile = Server.MapPath(newFile);
doc.SaveAs(physicNewFile,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
catch (Exception ex)
if (doc != null)
doc.Close();//关闭文档
if (app != null)
app.Quit();//退出应用程序
阅读(...) 评论()如何同时自动把EXCEL表中所有列调整到合适宽度_百度知道
如何同时自动把EXCEL表中所有列调整到合适宽度
就是批量的ABCDEFG这么多列同时调整到合适大小而不是一个一个的双击A | B 中间的 | 要批量调整
  1、选中表格所有列,点击“格式”-“列”-“最适合的列宽”即可。  2、全选各列后,鼠标移到某两列中间边框线,双击亦可。
采纳率:82%
来自团队:
选中全部的想调整的列,然后在列缝之间双击即可
本回答被提问者采纳
excel中让表格自动应用页面宽度,是没有这个功能的,只有word新建表格是有这功能。但可以通过设置,来达到自己想要的表格宽度:1、word2007版要调整单元格的宽度的话,就选定需要调整宽带的列的范围,再点击菜单-开始-右边的格式栏-下拉-里面有列宽,也有行高,单位是毫米,1cm就填入10,确定就可以了。2、word2003版直接在菜单-格式-就有列和行的选择,里面就有列宽和行高,单位和2007版一样的,都是毫米为单位的。
选最后一列,按住Shift键,然后在任何一个字母上单击右键,选择列宽鼠标左键线选第一列
然后鼠标右键
设置你需要的值!
选中多列,光标放在列与列之间变为双黑箭头,双击即可。
同时选中这些列,然后双击最后一个|
收起其他5条回答
为您推荐:
其他类似问题
excel的相关知识
等待您来回答C# 操作word表格、图片、文字格式大全_中华文本库
第2页/共4页
newTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleS
newTable.Columns[1].Width = 100f;
newTable.Columns[2].Width = 220f;
newTable.Columns[3].Width = 105f;
//填充表格内容
newTable.Cell(1, 1).Range.Text = "产品详细信息表";
newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体
//合并单元格
newTable.Cell(1, 1).Merge(newTable.Cell(1, 3));
WordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalC//垂直居中
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphC//水平居中
//填充表格内容
newTable.Cell(2, 1).Range.Text = "产品基本信息";
newTable.Cell(2, 1).Range.Font.Color = Word.WdColor.wdColorDarkB//设置单元格内字体颜色
//合并单元格
newTable.Cell(2, 1).Merge(newTable.Cell(2, 3));
WordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalC
//填充表格内容
newTable.Cell(3, 1).Range.Text = "品牌名称:";
newTable.Cell(3, 2).Range.Text = BrandN
//纵向合并单元格
newTable.Cell(3, 3).Select();//选中一行
object moveUnit = Word.WdUnits.wdL
object moveCount = 5;
object moveExtend = Word.WdMovementType.wdE
WordApp.Selection.MoveDown(ref moveUnit, ref moveCount, ref moveExtend);
WordApp.Selection.Cells.Merge();
//插入图片
string FileName = P//图片所在路径
object LinkToFile =
object SaveWithDocument =
object Anchor = WordDoc.Application.Selection.R
WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;//图片宽度
WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;//图片高度
//将图片设置为四周环绕型
第2页/共4页
寻找更多 ""

我要回帖

更多关于 电脑内存怎么扩大 的文章

 

随机推荐