【问题标题】:How to create a document and fill it with textboxes based on x and y coords or pixels?如何创建文档并使用基于 x 和 y 坐标或像素的文本框填充它?
【发布时间】:2014-02-07 14:09:31
【问题描述】:

我正在尝试创建一个模板,以基于坐标或像素或厘米在空白文档上打印一些信息,wtv 是可能的。

为什么?我有一些会计表格,手工填写不好。我想知道是否可以使用与文档中的文本框位置相关的一些参数创建一个函数。

例如。 txtName 转到文档中的 (3,15) 位置。可能需要定义文档的大小

如果可以的话,你推荐什么语言?

【问题讨论】:

    标签: ms-word openxml docx


    【解决方案1】:

    是的,有可能。

    如果您使用 Microsoft Word 将文本框插入空白文档,然后将其保存并检查生成的 docx,您会看到 Word 以 2 种格式插入文本框:

            <mc:AlternateContent>
          <mc:Choice Requires="wps">
            <w:drawing>
              <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251659264" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="44014479" wp14:editId="7FACADD8">
                <wp:simplePos x="0" y="0"/>
                <wp:positionH relativeFrom="column">
                  <wp:align>center</wp:align>
                </wp:positionH>
                <wp:positionV relativeFrom="paragraph">
                  <wp:posOffset>0</wp:posOffset>
                </wp:positionV>
                <wp:extent cx="2374265" cy="1403985"/>
                <wp:effectExtent l="0" t="0" r="22860" b="23495"/>
                <wp:wrapTopAndBottom/>
                <wp:docPr id="307" name="Text Box 2"/>
                <wp:cNvGraphicFramePr>
                  <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
                </wp:cNvGraphicFramePr>
                <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                  <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                    <wps:wsp>
                      <wps:cNvSpPr txBox="1">
                        <a:spLocks noChangeArrowheads="1"/>
                      </wps:cNvSpPr>
                      <wps:spPr bwMode="auto">
                        <a:xfrm>
                          <a:off x="0" y="0"/>
                          <a:ext cx="2374265" cy="1403985"/>
                        </a:xfrm>
                        <a:prstGeom prst="rect">
                          <a:avLst/>
                        </a:prstGeom>
                        <a:solidFill>
                          <a:srgbClr val="FFFFFF"/>
                        </a:solidFill>
                        <a:ln w="9525">
                          <a:solidFill>
                            <a:srgbClr val="000000"/>
                          </a:solidFill>
                          <a:miter lim="800000"/>
                          <a:headEnd/>
                          <a:tailEnd/>
                        </a:ln>
                      </wps:spPr>
                      <wps:txbx>
                        <w:txbxContent>
                          <w:p w:rsidR="006C2E97" w:rsidRDefault="006C2E97">
                            <w:proofErr w:type="gramStart"/>
                            <w:r>
                              <w:t>YOUR CONTENT GOES HERE</w:t>
                            </w:r>
                          </w:p>
                        </w:txbxContent>
                      </wps:txbx>
                      <wps:bodyPr rot="0" vert="horz" wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720" anchor="t" anchorCtr="0">
                        <a:spAutoFit/>
                      </wps:bodyPr>
                    </wps:wsp>
                  </a:graphicData>
                </a:graphic>
                <wp14:sizeRelH relativeFrom="margin">
                  <wp14:pctWidth>40000</wp14:pctWidth>
                </wp14:sizeRelH>
                <wp14:sizeRelV relativeFrom="margin">
                  <wp14:pctHeight>20000</wp14:pctHeight>
                </wp14:sizeRelV>
              </wp:anchor>
            </w:drawing>
          </mc:Choice>
    
    
          <mc:Fallback>
            <w:pict>
              <v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe">
                <v:stroke joinstyle="miter"/>
                <v:path gradientshapeok="t" o:connecttype="rect"/>
              </v:shapetype>
              <v:shape id="Text Box 2" o:spid="_x0000_s1026" type="#_x0000_t202" style="position:absolute;margin-left:0;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top" >
                <v:textbox style="mso-fit-shape-to-text:t">
                  <w:txbxContent>
                    <w:p w:rsidR="006C2E97" w:rsidRDefault="006C2E97">
                      <w:r>
                        <w:t>YOUR CONTENT GOES HERE</w:t>
                      </w:r>
                    </w:p>
                  </w:txbxContent>
                </v:textbox>
                <w10:wrap type="topAndBottom"/>
              </v:shape>
            </w:pict>
          </mc:Fallback>
        </mc:AlternateContent>
      </w:r>
    

    您可以使用 w:drawing 或 w:pict 语法。我很喜欢 w:pict 的 @style

    作为第一步,您需要在 Word 中了解框的位置 - 我猜您希望它们位于页面上,而不是段落上。

    然后,只需以您选择的语言复制 XML。

    你可以:

    • 解压缩,操作,然后重新压缩
      • 使用 XML 感知工具进行操作
      • 或者在没有那个的情况下进行操作
    • 或使用库,例如​​:
      • 对于 .NET,Microsoft 的 Open XML SDK
      • 用于 Java、POI、docx4j
      • 对于 C,libopc 等等……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-06
      • 2023-03-30
      • 1970-01-01
      • 2023-02-01
      • 2020-06-28
      • 2010-11-03
      • 1970-01-01
      • 2011-12-31
      相关资源
      最近更新 更多