我可以使用JavaScript上传文字文件并使用.replace,然后另存为新文档 [英] Using JavaScript, Can I upload a word file and use .replace then save as new document
问题描述
使用JavaScript,我想上载word文档和/或浏览本地计算机上的文件并查看内容...然后我想用不同的文本替换内容.
Using JavaScript I would like to upload a word document and/or browse for file on local machine and view the contents... I would then like to replace the contents with different text.
这是我要使用的文字替换的摘录.
Here is a snippet of the text replace I want to use.
<button onclick="myFunction()">Convert</button>
<script>
function myFunction()
{
var str = document.getElementById("source").value;
var res =
str.replace(/a/g, "ა")
.replace(/b/g, "ბ")
.replace(/g/g, "გ")
//+ more letters for entire alphabet
document.getElementById("source").value=res;
}
</script>
我想知道的是,是否有可能获取Word文档文件的内容,将所有字母都更改为格鲁吉亚字符(如果可能,请保留格式),然后另存为新的Word文档?
What I would like to know is if it's possible to get the contents of a word document file, change all of the letters into Georgian characters (whilst retaining formatting if possible) then to save as a new word document?
推荐答案
For docx you could use DOCX.js https://github.com/stephen-hardy/DOCX.js
这篇关于我可以使用JavaScript上传文字文件并使用.replace,然后另存为新文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!