标签: docx

Apache POI:如何设置字段的字体样式(PAGE、PAGENUM、PAGEREF...)

从另一个(已回答的)问题中,我学会了如何将页面计数器添加到 Word 文档中。此外,我需要在字段(即页面计数器)上设置字体系列样式(颜色、粗体、斜体、下划线...)。如何做到这一点?

CTSimpleField ctSimpleField = paragraph.getCTP().addNewFldSimple();
Run Code Online (Sandbox Code Playgroud)

CTSimpleField 不提供直接设置这些属性的方法。

原始问题:如何在使用apache poi api创建word文档时以X of Y格式添加页码?

import java.io.*;

import org.apache.poi.xwpf.usermodel.*;

import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;

public class CreateWordHeaderFooter {

 public static void main(String[] args) throws Exception {

  XWPFDocument doc= new XWPFDocument();

  // the body content
  XWPFParagraph paragraph = doc.createParagraph();
  XWPFRun run=paragraph.createRun();  
  run.setText("The Body:");

  paragraph = doc.createParagraph();
  run=paragraph.createRun();  
  run.setText("Lorem ipsum.... page 1");

  paragraph = doc.createParagraph();
  run=paragraph.createRun();
  run.addBreak(BreakType.PAGE); 
  run.setText("Lorem ipsum.... page 2");

  paragraph = doc.createParagraph();
  run=paragraph.createRun();
  run.addBreak(BreakType.PAGE); 
  run.setText("Lorem ipsum.... page 3");

  // create header-footer
  XWPFHeaderFooterPolicy headerFooterPolicy …
Run Code Online (Sandbox Code Playgroud)

java apache ms-word docx apache-poi

1
推荐指数
1
解决办法
1252
查看次数

如何在 python-docx 中应用粗体和居中?

我正在使用 python-docx 将文本放入 MS Word 中。我可以将其设置为粗体或居中,但如何同时做到这两点。
这里加粗的是:

p=document.add_paragraph().add_run('test word')
p.font.size = Pt(16)
p.bold = True
Run Code Online (Sandbox Code Playgroud)

这是中心:

p=document.add_paragraph('test word')
p.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
Run Code Online (Sandbox Code Playgroud)

如何同时做到粗体和居中?

python docx python-docx

1
推荐指数
1
解决办法
4603
查看次数

使用 python 包 docx 将绘图直接添加到文档中

我正在绘制一些数据,我想自动生成报告。我可以保存该图,然后将其添加到我的文档中。但是,我更喜欢直接执行,而不保存步骤。浏览 python-docx 文档我怀疑这个包是否可行。还有别的办法吗?

我的代码现在看起来像这样

from docx import Document
from docx.shared import Inches
import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.savefig('test.png')

document = Document()
document.add_heading('Report',0)
document.add_picture('test.png', width=Inches(1.25))

document.save('report.docx')
Run Code Online (Sandbox Code Playgroud)

python matplotlib docx python-docx

1
推荐指数
1
解决办法
8689
查看次数

如何使用 Apache POI 将 docx 中的文本(标签)替换为 HTML?

我们将有一些模板 docx 文件,其中会有一些标签,例如 ${content}。我需要用 HTML 替换这个标签。

为此,我想在 XWPFDocument 中使用 altChunk 元素。按照How to add an altChunk element to a XWPFDocument using Apache POI 中的答案,我可以将 altChunk 放在 docx 的末尾。

我怎样才能用它替换我的标签?或者我可以使用任何其他库,可能是 docx4j?

UPD: 带有标签的模板 docx 文件由最终用户使用 MS Word 创建,如下所示: 示例 docx 模板

html java docx apache-poi

1
推荐指数
1
解决办法
4646
查看次数

如何在Flutter中获取文件的base64

我有一个文件路径字符串,例如

path = /data/user/0/com.digitalpathshalabd.school/cache/Shaiful_Islam.docx
Run Code Online (Sandbox Code Playgroud)

现在我想将文件转换为base64

我怎样才能做到这一点?

base64 docx flutter flutter-file

1
推荐指数
1
解决办法
7435
查看次数

尝试在docx文件中插入数字签名行

我正在尝试在word文档的openxml(docx)版本中插入数字签名行.我没有得到任何错误,但我意识到我可能会错过一步.这是我的代码.这是一个Windows窗体应用程序.有人能告诉我如何正确地将数字签名行附加到Run实例吗?// S //用作我们想要插入数字签名行的标记.使用foreach语句很容易找到它.

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Vml.Office;
using DocumentFormat.OpenXml.Wordprocessing;

namespace KeywordSearch
{
    public partial class Form1 : Form
    {
        FileInfo[] tempfiles;
        List<FileInfo> files = new List<FileInfo>();

        public Form1()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string fileName = txtPath.Text;
            using (WordprocessingDocument doc =
            WordprocessingDocument.Open(fileName, false))
            {
                foreach (Text t in doc.MainDocumentPart.Document.Body.Descendants<Text>())
                {
                    if (t.Text == "//S//")
                    {
                        lbxResults.Items.Add(t.Text);

                        Run r …
Run Code Online (Sandbox Code Playgroud)

c# ms-word docx openxml

0
推荐指数
1
解决办法
4466
查看次数

将ZipEntry复制到新ZipFile的惯用方法是什么?

我正在编写一个工具来在DOCX文件中进行一些小文本替换,这是一种压缩格式.我的方法是ZipEntry使用a将原始文件中的条目内容复制到修改后的文件中ZipOutputStream.对于大多数DOCX文件,这种方法效果很好,但偶尔我会遇到ZipException有关我写的内容与其中包含的元信息ZipEntry(通常是压缩大小的差异)之间的差异的问题.

这是我用来复制内容的代码.为简洁起见,我删除了错误处理和文档处理; 到目前为止,我还没有遇到过文档条目的问题.

ZipFile         original = new ZipFile(INPUT_FILENAME);
ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(OUTPUT_FILE));
Enumeration     entries = original.entries();
byte[]          buffer = new byte[512];
while (entries.hasMoreElements()) {
    ZipEntry    entry = (ZipEntry)entries.nextElement();
    if  ("word/document.xml".equalsIgnoreCase(entry.getName())) {
        //perform special processing
    }
    else{
        outputStream.putNextEntry(entry);
        InputStream in = original.getInputStream(entry);
        while (0 < in.available()){
            int read = in.read(buffer);
            outputStream.write(buffer,0,read);
        }
        in.close();
    }
    outputStream.closeEntry();
}
outputStream.close();
Run Code Online (Sandbox Code Playgroud)

ZipEntry对象直接复制ZipFile到另一个对象的正确或惯用方法是什么?

java zip copy docx

0
推荐指数
1
解决办法
4915
查看次数

Java版本控制

我使用docx4j来加载,操作和保存Word文件.一切都很完美,但有一件事我不知道如何实现它.我想要的是版本控制 - 这意味着如果您保存文档,则可以恢复该文档的早期版本(例如,仅保存delta).也许你可以描述它应该像SVN或Git,你可以回到你的文件的早期版本.问题是我不知道有任何可能实现这一点.所以我希望你们中的任何人都可以帮助我.如果任何人至少知道一个包或其他东西可以通常使用文件而不是特别是docx文件,那就没关系了.谢谢你的帮助!

编辑:对不起,我的问题不精确.这是我在这里的第一篇文章,将来我会改进;)

java api version-control version docx

0
推荐指数
1
解决办法
1559
查看次数

将docx,doc转换为base64 android

我想获取docx文件,如下所示

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == MainActivity.RESULT_OK) {

        if (resultCode == RESULT_OK) {
            // Get the Uri of the selected file
            Uri uri = data.getData();
            String uriString = uri.toString();
            File myFile = new File(uriString);
            String path = myFile.getAbsolutePath();
            filepath =path;
            String displayName = null;

            if (uriString.startsWith("content://")) {
                Cursor cursor = null;
                try {
                    cursor = this.getContentResolver().query(uri, null, null, null, null);
                    if (cursor != null && cursor.moveToFirst()) {
                        displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); …
Run Code Online (Sandbox Code Playgroud)

base64 android document doc docx

0
推荐指数
1
解决办法
3793
查看次数

下载docx文件时出错

我正在生成docx并从服务器下载.

private static function downloadFile($fileDir)
{
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . basename($fileDir));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($fileDir));
    readfile($fileDir);
}
Run Code Online (Sandbox Code Playgroud)

这是保存功能.如果我从服务器打开临时目录中的文件,它的工作原理.但下载后,我有错误"文件已损坏".我尝试恢复文件,然后恢复所有确定.错误在哪里?

php docx

0
推荐指数
1
解决办法
114
查看次数