【问题标题】:how to get the count of rows from adynamically created html page,using c#如何从动态创建的html页面中获取行数,使用c#
【发布时间】:2014-08-26 10:25:56
【问题描述】:

我有一些用于生成报告的 html 模板。

首先,我通过按某种顺序合并这些模板来生成一个 html 页面,然后我得到一个作为字符串的最终 Html 页面作为我的输出,这是使用 c# 完成的。

稍后我会将此 html 字符串转换为 PDF,方法是将其转换为 aspose 文档,然后再转换为 pdf。这部分使用 c#.net 和 aspose 完成。

我需要的是,每个页面由大约 20 行组成。我需要这样设置。每页应该只包含 20 行,(这些每一行也有内表和行)。但我想根据主行计数,并且在一个页面中它应该只有 20 个。

所以从 html 页面或字符串格式的 html 页面,有没有办法在每 20 个主要行之后设置一个分页符。 我只使用 aspose.word 而不是 aspose.pdf。

在每 20 个主表行之后,我想添加分页符。 我已将此 html 页面生成为字符串,所以有什么方法可以检查主表行的计数并在该字符串中添加分页符。

【问题讨论】:

  • 没看懂问题,是每20行分割一次,其中一行代表换行符所在的位置,还是每20个主表行分割一次?
  • 在每 20 个主表行上,我想添加一个分页符。
  • 你想做什么?在 html 中放入“分页符”?这是什么意思,溢出到2个不同的页面或?你不能在 html 中真正做“分页符”。
  • 我已经将此html页面生成为一个字符串,所以有没有办法检查主表行的计数并在该字符串中添加分页符。
  • 是的,将页面一分为二,通过添加分页符,我希望一页中只有 20 个主表行

标签: c# html aspose


【解决方案1】:

嗯,你的查询不是很清楚。您是否需要在 HTML 字符串中包含分页符。这在您的场景中可能非常复杂,因为您需要检查行标签,并且在特定计数之后您需要包含一个中断。当您也使用子表时,这将变得更加困难。

如果您正在使用 Aspose.Words for .NET 并希望 split the tables 到 word 文档中的新页面,您可以检查以下代码:

//Open document and create DocumentBuilder
Document doc = new Document(@"d:\\data\\Tables.docx");

DocumentBuilder buildr = new DocumentBuilder(doc);

//Get table from document
Table tab = doc.FirstSection.Body.Tables[0];

//We should split our table and insert breaks between parts of table.
int count = 0;
Table clone = (Table)tab.Clone(false);

int total = tab.Rows.Count % 20;

while (tab.Rows.Count  > 1)
{
    if (tab.Rows.Count > total)
    {
        clone.AppendChild(tab.FirstRow);
    }
    else
    {
        break;
    }
    if (count == 19 )
    {
        //Insert empty paragraph after original table
        Paragraph par = new Paragraph(doc);
        tab.ParentNode.InsertBefore(par, tab);

        //Insert newly created table after paragraph
        par.ParentNode.InsertBefore(clone, par);

        //Move document builder cursor to the paragraph
        buildr.MoveTo(par);

        //And insert PageBreak also you can use SectionBreakNewPage
        buildr.InsertBreak(BreakType.PageBreak);
        count = 0;
        clone = (Table)tab.Clone(false);

    }
    else
    {
        count = count + 1;
    }
}

//Save output document
doc.Save(@"d:\\data\\out.docx");

附:我是 Aspose 的社交媒体开发人员。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多