【发布时间】:2016-05-22 23:20:39
【问题描述】:
这是我在 NSAttributedString 类中发现的奇怪行为。根据文档,该类的对象可以产生各种类型的数据。我想将我的文本转换为 docx 现代格式。再次根据文档,我应该使用 NSOfficeOpenXMLTextDocumentType 文档属性。所以我这样做:
// produce an NSAttributedString with all of the indents have set
let stringToConvert = currentDocument.computePrintableAttributedString(forProduct: product)`
// now create a document attributes dictionary
let documentAttributes = [NSDocumentTypeDocumentAttribute : NSOfficeOpenXMLTextDocumentType]
// finally convert the string into the docx data
do {
let convertedData = try stringToConvert.dataFromRange(fullLength, documentAttributes: documentAttributes)
} catch {
print(error)
}
一切正常。我将数据写入文件。并在 MS Word 中打开它。一切看起来都很好......除了文档丢失了属性字符串段落样式的所有尾部缩进。
我做错了什么?如何在导出的 docx 文档中保留尾部缩进?
我已经尝试了 NSRTFTextDocumentType 属性,并且我得到了一个格式非常好的 rtf 文件,其中所有的尾部缩进都到位。
NSOfficeOpenXMLTextDocumentType 缺少什么?
【问题讨论】:
-
也许可以提供一个文本示例(带有尾部缩进),以便可以重现该行为。
标签: swift cocoa cocoa-touch nsattributedstring