Cell类表明Word中定义的表格单元格对象,是表格的重要组成部分。要对这个对象进行写入操做时只能经过Table类对象的openCellRC (rowIndex, columnIndex) 方法获取Cell对象,方法中的参数分别表明行的索引和列的索引,从“1”开始。字体
Cell cell = table.openCellRC(rowIndex, columnIndex);
要读取这个对象时既能够经过Table类对象的openCellRC (rowIndex, columnIndex)方法获取,又能够经过Table类对象的 table.getCells().get(index)方法获取,index表明Cell的索引,从0开始。spa
它表明Word中定义的表格单元格对象,注意:同Table类同样,WordWriter和WordReader中都有Cell类。要对Cell对象进行设置时使用的是WordWriter命名空间中的openCellRC (rowIndex, columnIndex)方法;要获取Cell对象的值时使用的是WordReader命名空间中的openCellRC (rowIndex, columnIndex)方法。code
注:openCellRC方法中的参数分别表明行的索引和列的索引,从“1”开始。对象
Cell类进行写入操做时blog
Cell类进行读取操做时索引
Cell类进行写入操做时对象的属性开发
Cell类对象属性部分使用Java代码:get
Cell cell = table.openCellRC(2,2);//第三行第二列的单元格,table为Table类对象 //cell.getBorder().setBorderType(WdBorderType.wdFullGrid);//边框样式 cell.getFont().setSize(20);//字体大小 cell.getShading().setBackgroundPatternColor(Color.green);//底纹颜色 cell.setValue("aaa");//赋值 cell.setVerticalAlignment(WdCellVerticalAlignment.wdCellAlignVerticalCenter);// 设置垂直对齐方式
(效果图)string
Cell类对象属性部分使用C#代码:it
Cell cell = table.OpenCellRC(2,1); cell.Border.LineColor = Color.Gray;//边框线颜色 cell.Font.Bold = true;//字体加粗 cell.Font.Size = 12; cell.Value = "123"; cell.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalBottom;//垂直方向对齐方式
Cell类进行读取操做时对象的属性
Cell类对象属性部分使用Java代码:
... ... Cell cell = table.openCellRC(2,3); //获取某个Cell对象,table为Table类对象 int columnIndex = cell.getColumnIndex(); //获取cell所在列的索引 int rowIndex = cell.getRowIndex(); //获取cell所在行的索引 List<Shape> shapes = cell.getShapes(); //获取Cell 里包含的 Shape 集合 String cellValue = cell.getValue(); //获取cell的值 ... ...
Cell类对象属性部分使用C#代码:
... ... Cell cell = table.OpenCellRC(3,2); //获取某个Cell对象,table为Table类对象 int columnIndex = cell.ColumnIndex; //获取cell所在列的索引 int rowIndex = cell.RowIndex; //获取cell所在行的索引 ArrayList shapes = cell.Shapes; //获取Cell 里包含的 Shape 集合 string cellValue = cell.Value; //获取cell的值 ... ...
Cell类进行写入操做时对象的方法:
MergeTo:将指定单元格与另外一表格单元格合并,成为一个单独的表格单元格
Java代码:
... ... Cell cell = table.openCellRC(2,2); cell.mergeTo(2,3); ... ...
ASP.NET代码:
... ... Cell cell = table.OpenCellRC(2,2); cell.MergeTo(2,3); ... ...
合并后显示以下图绿色区域所示:
Cell类进行读取操做时对象的方法
OpenShape:打开指定的图形,并返回 Shape 对象
Java代码:
Shape shape = cell.openShape(1);//参数为Shape的索引
ASP.NET代码:
Shape shape = cell.OpenShape(1);//参数为Shape的索引