如何从* .docx文件中删除所有无关的空格? [英] How can I remove all extraneous spaces from a *.docx file?
问题描述
我想从.docx文件中删除所有多余的空格。如果有两个以上的情况,为了完成这个手动操作,我需要多次搜索并替换两个空格来获取所有这些空间,而且很难说出我什么时候完成。
这段代码使用了docx库,完成了它:
<$ p private void RemoveSuperfluousSpaces(string filename)
{
bool superfluousSpacesFound = true;
using(DocX document = DocX.Load(filename))
{
List< int> multipleSpacesLocs;
while(superfluousSpacesFound)
{
document.ReplaceText(,);
multipleSpacesLocs = document.FindAll();
superfluousSpacesFound = multipleSpacesLocs.Count> 0;
}
document.Save();
$ b $ p $从 here 。
I want to remove all superfluous spaces from a .docx file. If there are cases where there are more than two, to accomplish this manually I need to do a search-and-replace for two spaces multiple times to get all of them, and it's hard to tell when I'm "finished."
This code, using the docx library, accomplishes it:
private void RemoveSuperfluousSpaces(string filename)
{
bool superfluousSpacesFound = true;
using (DocX document = DocX.Load(filename))
{
List<int> multipleSpacesLocs;
while (superfluousSpacesFound)
{
document.ReplaceText(" ", " ");
multipleSpacesLocs = document.FindAll(" ");
superfluousSpacesFound = multipleSpacesLocs.Count > 0;
}
document.Save();
}
}
Download docx from here.
这篇关于如何从* .docx文件中删除所有无关的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!