mini-software / miniword Goto Github PK
View Code? Open in Web Editor NEW.NET Word(docx) exporting template engine without COM+ & interop (support Linux and Mac)
License: Apache License 2.0
.NET Word(docx) exporting template engine without COM+ & interop (support Linux and Mac)
License: Apache License 2.0
异常信息:
DocumentFormat.OpenXml.Packaging.OpenXmlPackageException:“The specified package is invalid. The main part is missing.”
希望能支持转化pdf
如果在表格內有換行資料時,產生出來的內容會多出好幾個換行
原本預期
index | Second Header |
---|---|
1 | line1 line2 line3 |
實際結果
index | Second Header |
---|---|
1 | line1 line2 line3 |
执行出错,提示 :File contains corrupted data
很多时候,导出的会是富文本,里面包含有样式的文本,还有可能包含图片,涉及到图片导出来的最大尺寸问题
遇到很奇怪的情况,即使整个 {{tagname}}
使用格式刷,文本替换还是不生效。
查看document.xml
,里面的实际情况为:
<w:r>
<w:rPr>
<w:rFonts w:hint="eastAsia" w:ascii="宋体" w:hAnsi="宋体" w:cs="宋体"/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:t>{</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:cs="宋体"/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:t>{type}}</w:t>
</w:r>
Samples中的Demo4也测试了类似的情况。
我写了下面一个小方法,(模仿AvoidSplitTagText
),尝试处理这种情况:
private static void MergeTagInMultiText(OpenXmlElement xmlElement)
{
var texts = new LinkedList<Text>(xmlElement.Descendants<Text>());
var node = texts.First;
while (node != null)
{
if (node.Next == null) goto next;
var next = node.Next.Value;
if (!node.Value.InnerText.EndsWith("{{") && node.Value.InnerText.EndsWith("{"))
{
if (next.InnerText.StartsWith("{") && !next.InnerText.StartsWith("{{"))
{
node.Value.Text = node.Value.InnerText + "{";
next.Text = next.InnerText.Substring(1) ;
}
}
else if (node.Value.InnerText.EndsWith("}") && !node.Value.InnerText.EndsWith("}}"))
{
if (next.InnerText.StartsWith("}") && !next.InnerText.StartsWith("}}"))
{
node.Value.Text = node.Value.InnerText + "}";
next.Text = next.InnerText.Substring(1);
}
}
next:
node = node.Next;
}
}
在AvoidSplitTagText
之前使用这个方法处理了一下,之前不能渲染的地方可以正常渲染了(自己一个简单的例子)。
感觉大概是这种思路,将相邻的格子里面落单的}
或者{
跟前后的大部队合并起来,只是可能实现的粗糙了一点。
表格自定义样式,字体自定义样式
兼容换行问题:
若字符串中存在"\n"或"\r\n",在Word换行时会多一行。
此问题其它用户在issue中也已提到
https://github.com/mini-software/MiniWord/issues/25
超链接不支持数组:
当我想要插入超链接数组/列表时
最终的结果会在Word中显示以下字符串,无法插入超链接:
MiniSoftware.MiniWordHyperLink[] 或 System.Collections.Generic.List`1[MiniSoftware.MiniWordHyperLink]
当前版本暂无该功能,希望加入,感谢大佬
这是对于未来的功能设计建议
常用功能:
进度 | 功能 | 说明 | 用处/领域 | 代码建议 |
× | 简单生成Word | 文字,图片,表格,段落 | 简单文档,说明书,等要求不严格的地方 | MiniWord.SaveAs(string path, object value, WordType wordType); MiniWord.SaveAs(string path, WordInfo value, WordType wordType); |
× | 简单获取Word | 可以按需求提取简单纯文字,图片,表格,段落 | 简单需要获取文档信息地方 | WordInfo wordInfo = MiniWord.Query(string path); |
× | 简单合并Word | 一个或多个合并为一个 | MiniWord.Join(string path, params string[] path); | |
× | 导出为指定格式 | 生成txt,简单html | txt:简单翻译 html:简单在线预览 |
WordInfo.ToString() WordInfo.ToHtml() |
× | 简单查找文本 | 有助于解决:标签{{}}会拆分为{{Tag}}的问题 | private ??? Seek(string path, string value) | |
× | 水印 | 生成简单文字水印,图片水印 | 提升逼格 | MiniWord.SaveAs(string path, watermark : WordWatermark); |
√ | 简单或复杂替换 |
如題
希望可以用一個樣版,產生多筆資料到同一份word中,也可以插入分頁
目前用openxml太複雜做
<w:r>
<w:t>{{</w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:t>CreateDate</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
<w:r>
<w:t>}}</w:t>
</w:r>
<w:tc>
<w:tcPr>
<w:tcW w:w="1870" w:type="dxa"/>
</w:tcPr>
<w:p w14:paraId="53105C06" w14:textId="07109D26" w:rsidR="00B721B4" w:rsidRDefault="00B721B4">
<w:r>
<w:t xml:space="preserve">{{Name}} has </w:t>
</w:r>
<w:r w:rsidRPr="005F3C0A">
<w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
<w:t xml:space="preserve">{{Points}} </w:t>
</w:r>
<w:r>
<w:t>points</w:t>
</w:r>
</w:p>
</w:tc>
e,g http://deepoove.com/poi-tl/#_%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8
{{name}}
{{name.toUpperCase()}}
{{name == 'poi-tl'}}
{{empty?:'这个字段为空'}}
{{sex ? '男' : '女'}}
{{new java.text.SimpleDateFormat('yyyy-MM-dd HH:mm:ss').format(time)}}
{{price/10000 + '万元'}}
{{dogs[0].name}}
{{localDate.format(T(java.time.format.DateTimeFormatter).ofPattern('yyyy年MM月dd日'))}}
I tried a table with multiple columns (and placeholders) but I got the error:
"MiniWord doesn't support more than 1 list in same row"
希望能增加给word生成页眉页脚功能
<w:p w14:paraId="00F3FAAC" w14:textId="2EB54515" w:rsidR="00D362CD" w:rsidRDefault="00D362CD">
<w:r>
<w:rPr>
<w:rFonts w:hint="eastAsia"/>
</w:rPr>
<w:t>{{Co</w:t>
</w:r>
<w:r>
<w:t>ntent</w:t>
</w:r>
<w:r w:rsidR="001D405E">
<w:t>}</w:t>
</w:r>
<w:r>
<w:t>}</w:t>
</w:r>
</w:p>
<w:p w14:paraId="71A906B0" w14:textId="7C726FC1" w:rsidR="00D362CD" w:rsidRDefault="00D362CD"/>
<w:p w14:paraId="7FC15E02" w14:textId="3DD8C144" w:rsidR="00D362CD" w:rsidRDefault="00D362CD">
<w:r>
<w:t>{{Content2}</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:hint="eastAsia"/>
</w:rPr>
<w:t>}</w:t>
</w:r>
</w:p>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData" mc:Ignorable="w14 w15 wp14">
<w:body>
<w:p>
<w:pPr>
<w:pStyle w:val="2" />
<w:jc w:val="center" />
<w:rPr>
<w:rFonts w:hint="eastAsia" w:eastAsia="宋体" />
<w:lang w:val="en-US" w:eastAsia="zh-CN" />
</w:rPr>
</w:pPr>
<w:bookmarkStart w:id="0" w:name="_GoBack" />
<w:bookmarkEnd w:id="0" />
<w:r>
<w:rPr>
<w:rFonts w:hint="eastAsia" w:eastAsia="宋体" />
<w:lang w:val="en-US" w:eastAsia="zh-CN" />
</w:rPr>
<w:t>My</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:hint="eastAsia" w:eastAsia="宋体" />
<w:lang w:val="en-US" w:eastAsia="zh-CN" />
</w:rPr>
<w:t>{</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:hint="eastAsia" w:eastAsia="宋体" />
<w:sz w:val="54" />
<w:szCs w:val="54" />
<w:lang w:val="en-US" w:eastAsia="zh-CN" />
</w:rPr>
<w:t>{</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:hint="eastAsia" w:eastAsia="宋体" />
<w:lang w:val="en-US" w:eastAsia="zh-CN" />
</w:rPr>
<w:t>title</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:hint="eastAsia" w:eastAsia="宋体" />
<w:lang w:val="en-US" w:eastAsia="zh-CN" />
</w:rPr>
<w:t>}}</w:t>
</w:r>
</w:p>
<w:sectPr>
<w:pgSz w:w="12240" w:h="15840" />
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0" />
<w:cols w:space="720" w:num="1" />
<w:docGrid w:linePitch="360" w:charSpace="0" />
</w:sectPr>
</w:body>
</w:document>
MiniWord.Implment.cs
page row 88
// table.Append(newTr);
table.InsertAfter(newTr, tr);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.