美文网首页
iOS 写Word第三方库

iOS 写Word第三方库

作者: woo_5857 | 来源:发表于2023-06-12 11:46 被阅读0次

    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)

    当然,这也适用于Markdown:

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

    let att=try AttributedString(markdown: mD)

    try att.writeDocX(to: url)

    DocXOptions允许自定义DocX输出。

    您可以选择使用DocXOptions指定元数据:

    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)

    相关文章

      网友评论

          本文标题:iOS 写Word第三方库

          本文链接:https://www.haomeiwen.com/subject/clfqydtx.html