iOS 寫Word第三方庫

pod 'DocX-Swift'


https://github.com/shinjukunian/DocX

用法

let string = NSAttributedString(string: "This is a string", attributes: [.font: UIFont.systemFont(ofSize: UIFont.systemFontSize), .backgroundColor: UIColor.blue])

let url = URL(fileURLWithPath:"myPath")

try? string.writeDocX(to: url)

從iOS 15/macOS 12開始,您可以使用新的AttributedString。

var att=AttributedString("Lorem ipsum dolor sit amet")

att.font = NSFont(name: "Helvetica", size: 12)

att[att.range(of: "Lorem")!].backgroundColor = .blue

let url = URL(fileURLWithPath:"myPath")

try att.writeDocX(to: url)


當(dāng)然,這也適用于Markdown:

let mD="~~This~~ is a **Markdown** *string*."

let att=try AttributedString(markdown: mD)

try att.writeDocX(to: url)

DocXOptions允許自定義DocX輸出。

您可以選擇使用DocXOptions指定元數(shù)據(jù):

let font = NSFont(name: "Helvetica", size: 13)! //on macOS

let string = NSAttributedString(string: "The Foundation For Law and Government favours Helvetica.", attributes: [.font: font])

var options = DocXOptions()

options.author = "Michael Knight"

options.title = "Helvetica Document"

let url = URL(fileURLWithPath:"myPath")

try string.writeDocX(to: url, options:options)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容