为有中文需求的客户提供多渠道中文技术支持.

Thu Feb 23, 2023 1:42 am

导出富文本HTML,html中存在多个p标签的情况下,设置段落格式,只有第一个p标签会生效,其他的不会
Code: Select all
Paragraph para = sec.addParagraph();
para.appendHTML(chapterVO.getContent());
para.getFormat().setHorizontalAlignment(HorizontalAlignment.Justify);//设置两端对齐
//设置多倍行距 1.4倍
para.getFormat().setLineSpacingRule(LineSpacingRule.Multiple);
para.getFormat().setLineSpacing(16.8f);


下面的是富文本内容
Code: Select all
"<p style=\"margin-top: 0px; margin-bottom: 0px; text-indent: 2em; line-height: 1.86;\">wiajdoawjdiowdjwioriwajoiwwiaowiojiowj。</p>\n<p style=\"margin-top: 0px; margin-bottom: 0px; text-indent: 2em; line-height: 1.86;\">wiojdopiajdaoppokwdpokad。</p>\n<p style=\"margin-top: 0px; margin-bottom: 0px; text-indent: 2em; line-height: 1.86;\">wdapokwpoadkaw。</p>\n<p style=\"margin-top: 0px; margin-bottom: 0px; text-indent: 2em; line-height: 1.86;\"><br>\n</p>\n<p style=\"margin-top: 0px; margin-bottom: 0px; text-indent: 2em; line-height: 1.86;\">吴炯哇的交往基地啊我都i我。</p>\n<p style=\"margin-top: 0px; margin-bottom: 0px; text-indent: 2em; line-height: 1.86;\">我看i都怕我看都怕我看打破。</p>\n<p style=\"margin-top: 0px; margin-bottom: 0px; text-indent: 2em; line-height: 1.86;\">我打破瓦颇为看懂普瓦。</p>"

Last edited by hannibal22 on Thu Feb 23, 2023 7:12 am, edited 1 time in total.

hannibal22
 
Posts: 52
Joined: Wed Aug 17, 2022 7:01 am

Thu Feb 23, 2023 7:12 am

您好,

感谢您的留言。
调用appendHtml方法后,每个p标签都会形成一个新的段落,而您的代码设置了第一个p标签形成的段落,请参考下面的代码对所有p标签形成的段落设置格式。

Code: Select all
Document doc = new Document();

        Section section = doc.addSection();

        Paragraph para = section.addParagraph();

        String html = "<p>非常感谢您使用我们的 Spire.PDF for Java 产品。非常感谢您使用我们的 Spire.PDF for Java 产品。</p><p>非常感谢您使用我们的 Spire.PDF for Java 产品。非常感谢您使用我们的 Spire.PDF for Java 产品。</p>";
        para.appendHTML(html);

        //通过<p>标签的数量来统计段落的个数
        String splitStr = "<p>";
        int pNumber = 0;
        for (int i = 0; i < html.length() - splitStr.length(); i++) {
            if (html.substring(i, i + splitStr.length()).equals(splitStr)) {
                pNumber++;
            }
        }

        //获取appendhtml后第一个<p>标签所在的段落的index
        int indexPara = section.getParagraphs().indexOf(para);

      //循环为后面p标签产生的段落设置格式
        while (pNumber > 0) {
            Paragraph p = section.getParagraphs().get(indexPara);
            p.getFormat().setHorizontalAlignment(HorizontalAlignment.Justify);//设置两端对齐
            p.getFormat().setLineSpacingRule(LineSpacingRule.Multiple);
            indexPara++;
            pNumber--;
        }

        doc.saveToFile("output/new_Justify.docx", FileFormat.Docx);


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Thu Feb 23, 2023 7:47 am

请问一下,通过这种方法找出来的p标签中的文字,如何设置字体。
Code: Select all
 while (pNumber > 0) {
            Paragraph p = section.getParagraphs().get(indexPara);
            p.getFormat().setHorizontalAlignment(HorizontalAlignment.Justify);//设置两端对齐
            p.getFormat().setLineSpacingRule(LineSpacingRule.Multiple);
            indexPara++;
            pNumber--;
        }

hannibal22
 
Posts: 52
Joined: Wed Aug 17, 2022 7:01 am

Thu Feb 23, 2023 8:51 am

您好,

感谢您的反馈。
对于您的需求,参考下面代码:
Code: Select all
//循环为后面p标签产生的段落设置格式
  while (pNumber > 0) {
      Paragraph p = section.getParagraphs().get(indexPara);
      p.getFormat().setHorizontalAlignment(HorizontalAlignment.Justify);//设置两端对齐
      p.getFormat().setLineSpacingRule(LineSpacingRule.Multiple);

      //Create a characterFormat object
      CharacterFormat format = new CharacterFormat(doc);
      //Set font
      format.setFontName("宋体");
      format.setFontSize(16);

      //Loop through the childObjects of paragraph
      for (int j = 0; j < p.getChildObjects().getCount(); j ++)
      {
          if ( p.getChildObjects().get(j) instanceof TextRange)
          {
              TextRange tr = (TextRange) p.getChildObjects().get(j);
              //Apply character format
              tr.applyCharacterFormat(format);
          }
      }
      indexPara++;
      pNumber--;
  }


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Thu Feb 23, 2023 9:22 am

好的 谢谢

hannibal22
 
Posts: 52
Joined: Wed Aug 17, 2022 7:01 am

Fri Feb 24, 2023 1:19 am

不客气,希望您有美好的一天。 :D

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Feb 24, 2023 7:41 am

您好请问一下 ,像下面这种富文本内容,其中带了<table>标签的,这种情况下面的 获取p标签所在段落的index 就会出现问题,导致报错
Code: Select all
//获取appendhtml后第一个<p>标签所在的段落的index-------------------------(这里的index会返回-1)
        int indexPara = section.getParagraphs().indexOf(para);

      //循环为后面p标签产生的段落设置格式
        while (pNumber > 0) {
            Paragraph p = section.getParagraphs().get(indexPara);-----------------------------------(这里就会报错)
            p.getFormat().setHorizontalAlignment(HorizontalAlignment.Justify);//设置两端对齐
            p.getFormat().setLineSpacingRule(LineSpacingRule.Multiple);
            indexPara++;
            pNumber--;
        }




富文本内容:
Code: Select all
<table border="1" cellpadding="0" cellspacing="0" width="1341" height="1617" style="border-collapse: collapse; width: 1005.77pt; background-color: rgb(255, 255, 255); table-layout: fixed;" bordercolor="#000000">
  <colgroup><col width="37">
  <col width="323">
  <col width="81">
  <col width="84">
  <col width="116">
  <col width="118">
  <col width="62">
  <col width="60">
  <col width="199">
  <col width="90">
  <col width="165">
  </colgroup>
  <tbody>
    <tr height="19" style="height:14.25pt;">
      <td class="et8" height="19" width="37" x:str="" style="height:14.25pt;width:28.15pt;">序号</td>
      <td class="et9" width="323" x:str="" style="width:242.70pt;">BUG描述</td>
      <td class="et9" width="81" x:str="" style="width:61.00pt;">提出人</td>
      <td class="et10" width="84" x:str="" style="width:63.60pt;">提交时间</td>
      <td class="et10" width="116" x:str="" style="width:87.70pt;">图片1</td>
      <td class="et10" width="118" x:str="" style="width:89.05pt;">图片2</td>
      <td class="et8" width="62" x:str="" style="width:46.80pt;">优先级</td>
      <td class="et8" width="60" x:str="" style="width:45.00pt;">结果</td>
      <td class="et20" width="199" x:str="" style="width:149.65pt;">备注</td>
      <td class="et20" width="90" x:str="" style="width:67.90pt;">解决方案</td>
      <td class="et20" width="165" x:str="" style="width:124.35pt;">完成修正时间</td>
    </tr>
    <tr height="38" style="height:28.50pt;">
      <td class="et2" height="38" x:num="1" style="height:28.50pt;">1</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">网站滚动鼠标缩放到175%及以上,上边的选项没了</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et21" width="165" x:num="44750" align="right" style="width:124.35pt;">2022/7/8</td>
    </tr>
    <tr height="38" style="height:28.50pt;">
      <td class="et2" height="38" x:num="2" style="height:28.50pt;">2</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">笔记本分辨率1920*1280,网站100%展示,字太小了(对比其他字体大小),截图如下</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">待确认</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et21" width="165" x:num="44750" align="right" style="width:124.35pt;">2022/7/8</td>
    </tr>
    <tr height="57" style="height:43.35pt;">
      <td class="et2" height="57" x:num="3" style="height:43.35pt;">3</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">导入图片提示</td>
      <td x:str="">金晖</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="56" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141933349001.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et21" width="165" x:num="44771" align="right" style="width:124.35pt;">2022/7/29</td>
    </tr>
    <tr height="57" style="height:42.75pt;">
      <td class="et2" height="57" x:num="4" style="height:42.75pt;">4</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">昨天录入的图片,今天无法显示</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="50" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141933172002.png"></span></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">问题出现为,网络图片直接复制,原链接地址失效,故无法展示</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">非问题</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="45" style="height:34.00pt;">
      <td class="et2" height="45" x:num="5" style="height:34.00pt;">5</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">表格与其上方文字无间距</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="43" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141934682003.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et21" width="165" x:num="44771" align="right" style="width:124.35pt;">2022/7/29</td>
    </tr>
    <tr height="40" style="height:30.00pt;">
      <td class="et2" height="40" x:num="6" style="height:30.00pt;">6</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">提交提示错误</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="38" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141935395004.png"></span></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="38" style="height:28.50pt;">
      <td class="et2" height="38" x:num="7" style="height:28.50pt;">7</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">序言添加内容,提交不成功,添加第一章,提交成功,但是序言内容丢失</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="58" style="height:44.15pt;">
      <td class="et2" height="58" x:num="8" style="height:44.15pt;">8</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">编辑区域太小,网页下方大量空白</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="57" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141937352005.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="69" style="height:51.95pt;">
      <td class="et2" height="69" x:num="9" style="height:51.95pt;">9</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">多个序言的话,不需要前边的小序号</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="68" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141937181006.png"></span></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="67" style="height:50.30pt;">
      <td class="et2" height="67" x:num="10" style="height:50.30pt;">10</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">标题和上下浮动条同时出现时,无法选择到增加目录</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="65" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141938536007.png"></span></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="76" style="height:57.00pt;">
      <td class="et2" height="76" x:num="11" style="height:57.00pt;">11</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">增加参考文献的添加按钮,和预览/提交放在一起,会产生歧义,以为是针对正文的内容,建议条件放到最下边去,或者至少放到跟参考文献一起</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="52" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141939673008.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="19" style="height:14.25pt;">
      <td class="et2" height="19" x:num="12" style="height:14.25pt;">12</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">预览功能需要默认预览位置为当前编辑位置</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="142" style="height:106.55pt;">
      <td class="et2" height="142" x:num="13" style="height:106.55pt;">13</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">红框处功能为鼠标移动到此处触发,但触发范围太小,建议扩大触发区域或改为点击触发</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="142" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141939384009.png"></span></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="38" style="height:28.50pt;">
      <td class="et2" height="38" x:num="14" style="height:28.50pt;">14</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">图片左对齐后,文字却自动上移到图片右侧区域</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="31" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141941492010.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">需要对文字手动换行操作</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et21" width="165" x:num="44771" align="right" style="width:124.35pt;">2022/7/29</td>
    </tr>
    <tr height="37" style="height:27.90pt;">
      <td class="et2" height="37" x:num="15" style="height:27.90pt;">15</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">图片与其上方文字无间距</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="35" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141942663011.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et21" width="165" x:num="44771" align="right" style="width:124.35pt;">2022/7/29</td>
    </tr>
    <tr height="55" style="height:41.60pt;">
      <td class="et2" height="55" x:num="16" style="height:41.60pt;">16</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">到下一级页面的软连接,与正文间距太大了</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="54" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141942952012.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="57" style="height:42.75pt;">
      <td class="et2" height="57" x:num="17" style="height:42.75pt;">17</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">正文与图片一起粘贴时,图片无法显示,且提交后网页持续转圈,无其他提示,只能手动退出编辑场景</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="39" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141943404013.png"></span></td>
      <td></td>
      <td class="et2"></td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">待确认</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et21" width="165" x:num="44771" align="right" style="width:124.35pt;">2022/7/29</td>
    </tr>
    <tr height="146" style="height:109.90pt;">
      <td class="et2" height="146" x:num="18" style="height:109.90pt;">18</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">预览展示的导航与编写的导航顺序不一致</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="146" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141943492014.png"></span></td>
      <td><span><img width="118" height="143" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141943949015.png"></span></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="57" style="height:42.75pt;">
      <td class="et2" height="57" x:num="19" style="height:42.75pt;">19</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">预览功能问题,输入内容后,没有提交(且没到10分钟自动保存),单击预览功能,新增的内容没有展示</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="46" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141944326016.png"></span></td>
      <td></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">预览时记作提交一次</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="57" style="height:42.75pt;">
      <td class="et2" height="57" x:num="20" style="height:42.75pt;">20</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">接着问题19场景,新增内容,没有提交(且没到10分钟自动保存),预览之后返回编辑界面,内容丢失</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td></td>
      <td></td>
      <td class="et2" x:str="">中</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">预览时记作提交一次</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="38" style="height:28.50pt;">
      <td class="et2" height="38" x:num="21" style="height:28.50pt;">21</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">预览界面没有按钮直接返回编辑界面,需要从首页返回</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td></td>
      <td></td>
      <td class="et2"></td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">不是问题</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">非问题</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="115" style="height:86.95pt;">
      <td class="et2" height="115" x:num="22" style="height:86.95pt;">22</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">表格保持原格式粘贴后,表格框线粗细不一,与原样式不一致(补充:表格框线样式被改变,且表格与其上下文字均无间距)</td>
      <td x:str="">谢山祎</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="74" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141945868017.png"></span></td>
      <td><span><img width="118" height="115" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141945230018.png"></span></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">待确认</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et21" width="165" x:num="44771" align="right" style="width:124.35pt;">2022/7/29</td>
    </tr>
    <tr height="137" style="height:103.40pt;">
      <td class="et2" height="137" x:num="23" style="height:103.40pt;">23</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">同级排序功能不可用</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="61" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141946472019.png"></span></td>
      <td><span><img width="118" height="137" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141946222020.png"></span></td>
      <td class="et2" x:str="">高</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
    <tr height="45" style="height:34.30pt;">
      <td class="et2" height="45" x:num="24" style="height:34.30pt;">24</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">创建章节时,不选择管理员时,默认当前创建责任人为管理员</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="43" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141947322021.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" x:str="" style="width:149.65pt;">待讨论</td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">不处理</td>
      <td class="et3" width="165" x:str="" style="width:124.35pt;">不处理</td>
    </tr>
    <tr height="66" style="height:50.10pt;">
      <td class="et2" height="66" x:num="25" style="height:50.10pt;">25</td>
      <td class="et3" width="323" x:str="" style="width:242.70pt;">目录缩起来很短,但是还是有拖动条</td>
      <td x:str="">杨逊</td>
      <td class="et11" x:num="44723" align="right">2022/6/11</td>
      <td><span><img width="116" height="65" src="https://ewebeditor-prod.obs.cn-south-1.myhuaweicloud.com:443/ewebeditor_image%2F20230222141948879022.png"></span></td>
      <td></td>
      <td class="et2" x:str="">低</td>
      <td class="et2" x:str="">CLOSED</td>
      <td class="et3" width="199" style="width:149.65pt;"></td>
      <td class="et3" width="90" x:str="" style="width:67.90pt;">已解决</td>
      <td class="et3" width="165" style="width:124.35pt;"></td>
    </tr>
  </tbody>
</table>
<p style="margin-top: 0px; margin-bottom: 0px; text-indent: 2em; line-height: 1.86;">据路透社报道,塞尔维亚已加入沙特阿拉伯和巴西的行列,批准了这笔价格687 亿美元的交易,该交易目前正在受到全球反垄断监管机构的审查。路透社还声称,微软可能会很快向欧盟监管机构做出让步,以帮助推动交易。<br>
<br>
IT之家了解到,微软收购动视暴雪的阻力目前主要是《使命召唤》系列游戏的竞争问题,索尼对该交易表达了反对意见。如果审查通过,这笔全现金收购将成为科技行业历史上规模最大、涉及金额最高的交易。<br>
<br>
欧盟委员会此前表示:“关键是要确保游戏生态系统保持活力,让这个正快速发展的行业的用户受益。我们必须确保未来和现有的 PC、游戏机视频游戏分销商以及 PC 操作系统的竞争对手仍有机会。”该机构需要在 2023 年 3 月 23 日之前决定是否批准这笔交易。<br>
</p>

hannibal22
 
Posts: 52
Joined: Wed Aug 17, 2022 7:01 am

Fri Feb 24, 2023 9:11 am

您好,

感谢您的反馈。
由于您html代码中最开始是表格,不是段落,所以para中存放的是table而不是段落,而这个代码(int indexPara = section.getParagraphs().indexOf(para); )表示在段落集合中查找para的位置,而para不是段落,因此没有找到该对象,所以返回-1,对于这个html代码,您如果是新建一个document,然后调用appenHtml()方法的话,您可以直接遍历段落集合,并为段落设置样式即可。参考如下:

Code: Select all
  //直接遍历所有段落
        for (int i = 0; i < section.getParagraphs().getCount(); i++) {
            Paragraph p = section.getParagraphs().get(i);
            //为段落设置样式
        }


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Feb 24, 2023 9:13 am

请问一下 这种方法,如何判断Paragraph p 中的内容都是什么类型的?标题,文本,表格,图片等?

hannibal22
 
Posts: 52
Joined: Wed Aug 17, 2022 7:01 am

Mon Feb 27, 2023 2:58 am

您好,

感谢您的反馈。
请注意表格与段落是同一级的,都直接属于Document的childObject, 对于您想要版本childObject的类型,请参考下面的代码:
Code: Select all
for (int k = 0; k < section.getBody().getChildObjects().getCount(); k++) {
            if (section.getBody().getChildObjects().get(k).getDocumentObjectType() == DocumentObjectType.Paragraph) {
                Paragraph p = (Paragraph)section.getBody().getChildObjects().get(k);
                     //获取段落样式名称
                String styleName = p.getStyle().getName();
                System.out.println("段落样式名称:"+styleName);

                //遍历段落
                for (int j = 0; j < p.getChildObjects().getCount(); j++) {
                    if (p.getChildObjects().get(j).getDocumentObjectType() == DocumentObjectType.Shape) {
                        System.out.println("这个段落的子对象是形状");
                    }
                    if (p.getChildObjects().get(j).getDocumentObjectType() == DocumentObjectType.Picture) {
                        System.out.println("这个段落的子对象是图片");
                    }
                    if (p.getChildObjects().get(j).getDocumentObjectType() == DocumentObjectType.Text_Range) {
                        System.out.println("这个段落的子对象是文本");
                    }
                    if (p.getChildObjects().get(j).getDocumentObjectType() == DocumentObjectType.TOC) {
                        System.out.println("这个段落的子对象是目录");
                    }
                }
            }
            if(section.getBody().getChildObjects().get(k).getDocumentObjectType() == DocumentObjectType.Table) {
                Table table = (Table)section.getBody().getChildObjects().get(k);
                System.out.println("这是表格");
            }
        }

对于遍历表格,请参考下面链接中的帮助文档:
https://www.e-iceblue.cn/docjava/get-te ... -java.html

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Feb 27, 2023 3:19 am

所以像是下面这种




1.第一级标题
今天天气真好。

标题和下面的正文,都是属于类型是DocumentObjectType.Text_Range文本的吗?有什么办法可以区分吗?想循环段落的时候分别设置这两个文字的样式。
其中标题是有para3.applyStyle(BuiltinStyle.Heading_3); 这种设置的

hannibal22
 
Posts: 52
Joined: Wed Aug 17, 2022 7:01 am

Mon Feb 27, 2023 10:26 am

您好,

感谢您的反馈。
对于您的需求,请参考下面的代码:
Code: Select all
for (int i = 0; i < section.getBody().getParagraphs().getCount(); i++) {
    Paragraph p = section.getParagraphs().get(i);
    String paraStyle = p.getStyle().getName();
    //当段落应用了样式“Heading 1”时
    if (paraStyle == "Heading 1") {
        //您想要的操作
    }else{
       
    }


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to 中文技术支持