![](/img/trans.png)
[英]Java - Compare 2 Word-Files (.docx): How do I get the Changes and remember the Change-Location in the XML?
[英]How do I get an Ampersand symbol into Word 2007 .docx XML file?
我正在根據客戶輸入以xml格式生成Word文檔,當然,每當使用&
時,它都會崩潰。 我嘗試用&
替換&
所有實例&
,然后&
從字面上顯示在我的Word文檔中。 這是我的代碼:
static String replace(String in) {
String ampersand = "&(?![a-zA-Z][a-zA-Z][a-zA-Z]?[a-zA-Z]?;)";
return in.replaceAll(ampersand,"&");
}
有任何想法嗎?
問題在於,“&”號在TOC和標題中的逸出方式不同。
在TOC中,它以&
轉義&
而標題中的轉義為\&
。
解決方案是在TOC和標題中以不同的方式逃離&符號:
您是否嘗試過用&
替換&符&
或&
(unicode)?
Word 2007本身具有&,因此您的問題必須是其他問題。
你的正則表達式對我來說似乎是錯誤的。 您為什么不這樣做:
static String replace(String in) {
return in.replace("&","&");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.