InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(TEMPLATE);
XWPFDocument document = new XWPFDocument(is);
List<IBodyElement> elements = document.getBodyElements();
for (int i = 0; i < elements.size(); i++) {
document.removeBodyElement(i);
}
CTBody body = document.getDocument().getBody();
CTSectPr docSp = body.getSectPr();
CTPageSz pageSize = docSp.getPgSz();
CTPageMar margin = docSp.getPgMar();
BigInteger pageWidth = pageSize.getW();
pageWidth = pageWidth.add(BigInteger.ONE);
BigInteger totalMargins = margin.getLeft().add(margin.getRight());
BigInteger contentWidth = pageWidth.subtract(totalMargins);
...
XWPFTable table = document.createTable(totalRows, totalColumns);
Run Code Online (Sandbox Code Playgroud)
从模板开始,我创建一个XWPFDocument并添加一个表.我怎么能在页面上添加多个表?也就是说,如何插入分页符?
我试图在java中读取一个文件,以下是代码:
public void readFile(String fileName){
try {
BufferedReader reader= new BufferedReader(new FileReader(fileName));
String line=null;
while((line=reader.readLine()) != null ){
System.out.println(line);
}
}catch (Exception ex){}
}
Run Code Online (Sandbox Code Playgroud)
它在txt文件的情况下工作正常.但是在docx文件的情况下,它是打印奇怪的字符.我怎样才能在Java中读取.docx文件.
尝试使用预定义的样式来样式化表,但是没有任何效果。我尝试了一个新创建的文档和一个从保存的模板创建的文档。使用SDK Productivity工具,我可以看到模板中有样式,但尚未应用。我尝试添加样式或直接设置样式,但似乎都没有用。
public static void CreateWordprocessingDocument(string fileName) {
string[,] data = {
{"Texas", "TX"},
{"California", "CA"},
{"New York", "NY"},
{"Massachusetts", "MA"}
};
using (var wordDocument = WordprocessingDocument.Open(fileName, true)) {
// We need to change the file type from template to document.
wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document);
var body = wordDocument.GetDocument().Body;
Table table = new Table();
TableProperties props = new TableProperties();
TableStyle tableStyle = new TableStyle { Val = "Light Shading Accent 1" };
props.TableStyle = tableStyle;
//props.Append(tableStyle);
table.AppendChild(props);
for (var i = 0; i …Run Code Online (Sandbox Code Playgroud) 我有一个简单的 Word 文件,我想使用documents4japi 将其转换为 PDF。已经搜索了几个小时,但还没有找到如何编写代码。我只需要一个基本的工作代码。
我在页脚中添加了一些页码。它在文档中正确可见。但是,如果我解压缩 docx 并检查 footer.xml,则只有一些随机页码存在。那么 MS-Word 如何能够正确显示页码,以及它存储所有页码的位置?
我想将字字节数组转换为 pdf 字节数组。我正在使用 Xceed.Words.NET 库
var stream = new MemoryStream(sourceFile.AttachedFile);
var doc = DocX.Load(stream);
var ms = new MemoryStream();
doc.SaveAs(ms);
var wByteArray = ms.GetBuffer();
Run Code Online (Sandbox Code Playgroud) 如何使用 POI API 或 Docx4j 将“.dotx”Word 模板转换为纯“.docx”?
我正在使用 HTML 和 Javascript 构建一个 Electron 应用程序。我希望应用程序在外部标准应用程序(如 Adobe Reader 和 Word)中自动打开下载的文件,例如 PDF、DOCX 等。是否有一个简单的 Javascript 函数来实现这个或者更好的方法?现在 Electron 会打开下载对话框,就像在 Chrome 中一样。不幸的是,我对 Javascript 没有很多经验,所以如果这是一个太简单的问题而您无法关注,我深表歉意。
const electron = require ('electron');
const url = require('url');
const path = require('path');
// In the main process.
const { app, Menu, BrowserWindow , shell } = require('electron')
// Listen for the app to be ready
app.on('ready', function() {
// Create new window
mainWindow = new BrowserWindow({});
// Load html into window
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: …Run Code Online (Sandbox Code Playgroud) 我们如何使用/不使用 python 将 PDF 转换为 docx。实际上我想自动转换大量文件,所以我需要一个API。
我使用过在线网站,例如: https: //pdf2docx.com/
https://online2pdf.com/pdf2docx
https://www.zamzar.com/convert/pdf-to-docx/
我无法直接使用那里的 api
我有什么作为输入: docx 以 byte64 格式记录原始字节。
我想要实现的是:从此文档中提取文本以进行进一步处理。
我试图遵循这个答案:从 python 中的 MS Word 文件中提取文本
我的代码片段:
base64_bytes = input.encode('utf-8')
decoded_data = base64.decodebytes(base64_bytes)
document = Document(decoded_data)
docText = '\n\n'.join([paragraph.text.encode('utf-8') for paragraph in document.paragraphs])
Run Code Online (Sandbox Code Playgroud)
该document = Document(decoded_data)行给了我以下错误:AttributeError: 'bytes' object has no attribute 'seek'
该decoded_data是按以下格式:b'PK\\x03\\x04\\x14\\x00\\x08\\x08\\x08\\x00\\x87@CP\\x00...
我应该如何格式化原始数据以从 docx 中提取文本?
docx ×10
java ×4
pdf ×4
apache-poi ×3
c# ×2
docx4j ×2
ms-word ×2
python ×2
api ×1
documents4j ×1
electron ×1
javascript ×1
openxml ×1
xml ×1