首页 > 其他分享 >在指定段落下增加表格

在指定段落下增加表格

时间:2023-07-07 22:26:11浏览次数:24  
标签:表格 rowIndex section 指定 columnIndex int table document 落下

Document document = new Document();
document.LoadFromFile("C:\\Users\\ZYB\\Desktop\\test.docx");
Section section = document.Sections[0]; // 获取第一个节
Paragraph title = null;
foreach (Paragraph paragraph in section.Paragraphs)
{
if (paragraph.Text == "法大师傅士大夫的")
{
title = paragraph;
break;
}
}
int rowCount = 3; // 行数
int columnCount = 4; // 列数

Table table = section.AddTable();
table.ResetCells(rowCount, columnCount);
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
{
TableRow row = table.Rows[rowIndex];
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
{
TableCell cell = row.Cells[columnIndex];
cell.AddParagraph().AppendText($"行{rowIndex + 1}, 列{columnIndex + 1}");
}
}

// 在指定标题段落后插入表格
section.Body.ChildObjects.Insert(section.Body.ChildObjects.IndexOf(title) + 1, table);

document.SaveToFile("d:/YourDocument.docx", FileFormat.Docx);

标签:表格,rowIndex,section,指定,columnIndex,int,table,document,落下
From: https://www.cnblogs.com/zyb-wzy/p/spire_doc_paraddtable.html

相关文章

  • ffmpeg指定屏幕区域录屏
    ffmpeg-hide_banner-loglevelerror-fgdigrab-show_region1-framerate6-video_size1914x930-offset_x1921-offset_y105-idesktop-pix_fmtyuv420pout6.mp4 -loglevelerror:只显示错误日志-video_size1914x930-offset_x1921-offset_y105:指定录屏......
  • vue3使用表格el-table-infinite-scroll.js:18 Uncaught (in promise) Error: [el-tabl
    先看下表格里面有没有这个el-scrollbar__wrapclass类 没有的话升级一下element-plus到最新的就行你可以先查看element-plus的版本npmview element-plus下载完之后 就有了......
  • layui表格内可编辑下拉框
    表格内可编辑下拉框扩展自别人的表格内下拉框一、列模板<scripttype="text/html"id="selectTpl"><divclass="inputdiv"><inputclass="layui-input"name="method"z-filter="input"data-tableName=&q......
  • 截取指定字符串前面或者后面的字符
    stringgddata=“af,cd”intindex=gddata.IndexOf(",");if(index>=0)//如果找到了指定字符{stringresult=gddata.Substring(0,index);//截取逗号前面的数据afstringresulet1......
  • spring注解之@PostConstruct在项目启动时执行指定方法
    学习资料:https://juejin.cn/post/7247543825534419000https://qa.1r1g.com/sf/ask/238458881/......
  • linux 中实现将指定列中多个连续的字符压缩为一个字符
     001、(base)[b20223040323@admin2test]$lsa.txt(base)[b20223040323@admin2test]$cata.txt##测试数据geneexonexonexonexon--------geneexonexon--------geneexonexonexonexon##将多个连续的exon......
  • SQL server字符串截取——根据指定符号截取字符串/截取文本
     ##-对字符串进行简单的处理,调用单个函数1.情况1:取字符串前X位用函数LEFT()SELECTLEFT([字段名],6)FROMDUAL;2.情况2:取字符串后X位用函数RIGHT()SELECTRIGHT([字段名],6)FROMDUAL;3.情况3:取字符串中间位数,例如,取身份证号中的出生年月用函数SUBSTRING()......
  • vue+element ui 表格选中特定行导出为excel
    1:使用场景:当选中表格中某几条数据(图中演示的为两行选中一行)进行导出为excel(如图二)2:安装依赖:npminstall--savexlsxfile-savernpminstall-Dscript-loader3:引入依赖文件:在src文件夹中创建名为excel的文件夹(注意大小写)将Blob.js、export2Excel.js两个js文件复制到exce......
  • ERP导出表格自定义格式R报表开发
    按照正常流程新建程序,画面修改上传,程序下载修改导入JAVA包,在global.import下 IMPORTcomIMPORTJAVAjava.net.URLIMPORTJAVAorg.apache.poi.ss.util.CellRangeAddressIMPORTJAVAorg.apache.poi.ss.util.RegionUtilIMPORTJAVAjava.io.InputStreamIMPORTJAVAjava......
  • Python 使用xlsxwriter绘制Excel表格
    最近在统计资产,正好看到了xlsxwriter这个表格生成模块,借此机会,熟悉一下,写点有趣的小案例,一开始想使用C++QT图形化开发一套自动化运维平台,但后来发现不仅消耗时间而且需要解决QTQssh远程模块的一些问题,后来没有使用QT做,xlsxwriter模块来做非常的简单,所以使用它。上班不能摸鱼,我要......