简体   繁体   English

如何使用 NPOI 创建目录?

[英]How to create a table of contents using NPOI?

I can barely find stuff for npoi when I do its for poi and its lacking.当我为 poi 做它时,我几乎找不到 npoi 的东西和它的缺乏。

I found this for poi:我为 poi 找到了这个:

CTP ctP = p.getCTP();
CTSimpleField toc = ctP.addNewFldSimple();
toc.setInstr("TOC \\h");
toc.setDirty(STOnOff.TRUE);enter code here`enter code here`

And was able to "adapt" into this并且能够“适应”这个

 XWPFParagraph p=doc.CreateParagraph();
 CT_P ctP = p.GetCTP();
 CT_SimpleField toc = ctP.***Field not working***;
 toc.instr="TOC \\h";
 toc.dirty=ST_OnOff.True;

(When I wrote Field not working, its 'cause i can't find the c# variation) (当我写 Field not working 时,是因为我找不到 c# 变体)

Also found还发现

XWPFDocument doc = new XWPFDocument();
doc.CreateTOC();

But can't find how to set it up.但是找不到如何设置它。

Might be simple but I'm still trying to learn and can't find proper documentation.(Also if you can help me add pagination would be awesome)可能很简单,但我仍在努力学习,找不到合适的文档。(另外,如果你能帮我添加分页就太好了)

Thanks in advance:)提前致谢:)

private static XWPFTable createXTable(XWPFDocument myDoc, DataTable dtSource)
    {
        int rowCount = dtSource.Rows.Count;
        int columnCount = dtSource.Columns.Count;
        CT_Tbl table = new CT_Tbl();
        XWPFTable xTable = new XWPFTable(table, myDoc, rowCount, columnCount);
        xTable.Width = 5000;
        
        for (int i = 0; i < rowCount; i++)
        {
            for (int j = 0; j < columnCount; j++)
            {
                xTable.GetRow(i).GetCell(j).SetParagraph(SetCellText(xTable, dtSource.Rows[i][j].ToString()));
            }
        }
        return xTable;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM