Spire表格

本文介绍了一种使用Spire插件批量处理固定格式Word文档的方法,实现了文档内容的自动读取,便于进一步的数据处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、需求

  遇到大量固定格式的word文档需求录入到系统中。量太打,决定用程序来导入。

2、选用插件Spire

3、实现

    因为是固定格式,所以能区到固定格子内的文本就可以了。代码如下

            Document doc = new Document(Server.MapPath("file/015010004.doc"));
            string str = "";
            foreach (Section section in doc.Sections)
            {
                foreach (Spire.Doc.Table table in section.Tables)
                {
                    foreach (Spire.Doc.TableRow row in table.Rows)
                    {
                        Spire.Doc.Collections.ParagraphCollection para = row.Cells[0].Paragraphs;
                        var a  = para[0].Text;
                    }
                }
            }        

  

转载于:https://www.cnblogs.com/Lv2014/p/6004486.html

Spire.Doc 中,你可以使用 Table 类来创建表格。以下是示例代码: ```csharp // 创建文档对象 Document document = new Document(); // 添加一个段落 Section section = document.AddSection(); Paragraph paragraph = section.AddParagraph(); // 创建表格对象 Table table = section.AddTable(); // 设置表格样式 table.TableFormat.Borders.BorderType = Spire.Doc.Documents.BorderStyle.Single; table.TableFormat.Borders.Color = Color.Black; table.TableFormat.Borders.LineWidth = 0.5f; // 添加表头行 TableRow headerRow = table.AddRow(); headerRow.Cells[0].AddParagraph().AppendText("姓名"); headerRow.Cells[1].AddParagraph().AppendText("年龄"); headerRow.Cells[2].AddParagraph().AppendText("地址"); // 添加数据行 TableRow dataRow = table.AddRow(); dataRow.Cells[0].AddParagraph().AppendText("张三"); dataRow.Cells[1].AddParagraph().AppendText("25"); dataRow.Cells[2].AddParagraph().AppendText("北京市朝阳区"); // 保存文档 document.SaveToFile("table.docx", FileFormat.Docx); ``` 在上述代码中,我们创建了一个文档对象,并添加了一个段落。然后使用 AddTable 方法创建了一个表格对象。接着,我们设置了表格的样式,如边框的类型、颜色和线宽。然后,我们添加了表头行和数据行,并在每个单元格中添加了段落并设置了相应的内容。最后,通过 SaveToFile 方法将文档保存为指定的文件格式(此处保存为 .docx)。 你可以根据需要调整代码中的具体内容和样式来适应你的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值