# DocX
DocX是一个小型框架,用于在iOS和macOS上将NSAttributedString转换为.docx Word文件。
## 动机
在iOS上,`NSAttributedString.DocumentType`仅支持HTML和富文本,而在macOS上可用的选项是.doc和.docx。即使在macOS上,.docx导出器也仅支持NSAttributedString的一部分属性。
该库用于[SimpleFurigana for macOS](https://itunes.apple.com/de/app/simple-furigana/id997615882?l=en&mt=12)和[SimpleFurigana for iOS](https://itunes.apple.com/de/app/simple-furigana/id924351286?l=en&mt=8)中,因此重点关注挂注(furigana)的导出。
## 安装
在您的`Package.swift`文件的`dependencies`中添加:
```
swiftCopy code
.package(name: "DocX", url: "https://github.com/shinjukunian/DocX.git", .branch("master"))
```
这需要Swift 5.3,该版本随Xcode12一起发布。 或者,在Xcode中通过`File->Swift Packages->Add Package Dependency`添加`DocX`,粘贴`https://github.com/shinjukunian/DocX.git`作为URL,并指定`master`作为分支。
## 用法
```
swiftCopy code
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)
```
您还可以使用`DocXOptions`指定元数据:
```
swiftCopy code
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和macOS)以了解用法和限制。 在iOS上,DocX还包括一个`UIActivityItemProvider`子类(`DocXActivityItemProvider`),用于通过`UIActivityViewController`导出.docx文件。
`NSAttributedString`没有分页的概念。对于手动分页,请使用:
```
swiftCopy code
try DocXWriter.write(pages:[NSAttributedString], to url:URL)
```
将每个`NSAttributedString`呈现为单独的页面。
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
在iOS上,`NSAttributedString.DocumentType`仅支持HTML和富文本,而在macOS上可用的选项是.doc和.docx。即使在macOS上,.docx导出器也仅支持NSAttributedString的一部分属性。 该库用于[SimpleFurigana for macOS](https://itunes.apple.com/de/app/simple-furigana/id997615882?l=en&mt=12)和[SimpleFurigana for iOS](https://itunes.apple.com/de/app/simple-furigana/id924351286?l=en&mt=8)中,因此重点关注挂注(furigana)的导出。 ## 安装 在您的`Package.swift`文件的`dependencies`中添加: ``` swiftCopy code .package(name: "DocX", url: "https://github.com/shinjukunian/DocX.git", .branch("mas
资源推荐
资源详情
资源评论
收起资源包目录
iOS和macOS上将NSAttributedString转换为.docx Word文件 (114个子文件)
0.8.5 41B
config 310B
description 73B
blank.docx 12KB
DocX-Examples-macOS.entitlements 311B
exclude 250B
FETCH_HEAD 786B
.gitignore 275B
.gitmodules 0B
DocX.h 554B
HEAD 178B
HEAD 178B
HEAD 32B
HEAD 23B
pack-79811f93b990241139d3a09428542b76ddcb67dc.idx 27KB
pack-5c105f9d68a91592792a08feca788d42887094d6.idx 1KB
pack-442e9f867c191d68cc5bdae9d2ffdbcb5acdbfda.idx 1KB
imageSize 138B
imageSize 41B
index 9KB
lenna.jpg 520KB
screenshot_mac.jpg 84KB
Contents.json 2KB
Contents.json 903B
Contents.json 62B
Contents.json 62B
LICENSE 1KB
master 178B
master 138B
master 41B
master 41B
README.md 2KB
pack-79811f93b990241139d3a09428542b76ddcb67dc.pack 945KB
pack-5c105f9d68a91592792a08feca788d42887094d6.pack 470KB
pack-442e9f867c191d68cc5bdae9d2ffdbcb5acdbfda.pack 658B
packed-refs 750B
project.pbxproj 43KB
project.pbxproj 23KB
Info.plist 1KB
Info.plist 1KB
Info.plist 834B
xcschememanagement.plist 737B
Info.plist 701B
Info.plist 701B
xcschememanagement.plist 473B
xcschememanagement.plist 449B
IDEWorkspaceChecks.plist 238B
IDEWorkspaceChecks.plist 238B
Picture1.png 94KB
Picture1.png 94KB
screenshot_iOS.png 56KB
.rels 590B
document.xml.rels 159B
Package.resolved 603B
Package.resolved 601B
Package.resolved 600B
TestDocument.rtf 3KB
pre-rebase.sample 5KB
update.sample 4KB
fsmonitor-watchman.sample 3KB
pre-commit.sample 2KB
prepare-commit-msg.sample 1KB
pre-push.sample 1KB
commit-msg.sample 896B
pre-receive.sample 544B
applypatch-msg.sample 478B
pre-applypatch.sample 424B
post-update.sample 189B
Main.storyboard 64KB
Main.storyboard 12KB
LaunchScreen.storyboard 2KB
DocXTests.swift 23KB
DocX_iOS_Tests.swift 13KB
DocXWriting.swift 6KB
AttributeElements.swift 5KB
ImageRelationship.swift 5KB
PlatformSpecific-iOS.swift 4KB
RubyAnnotationElement.swift 4KB
ParagraphElement.swift 4KB
DocumentRoot.swift 4KB
NSAttributedString+DocX-macOS.swift 4KB
NSParagraphStyle+Elements.swift 4KB
ComplexTextViewController.swift 3KB
DocXOptions.swift 3KB
TextViewViewController.swift 3KB
NSAttributedString+Extensions.swift 3KB
NSAttributedString+Writing.swift 2KB
AppDelegate.swift 2KB
NSTextAttachement+Extensions.swift 2KB
Package.swift 2KB
ViewController.swift 2KB
FontElements.swift 2KB
DocX.swift 2KB
NSUnderlineStyle+Elements.swift 1KB
DocXWriter.swift 1KB
NSAttributedString+DocX.swift 996B
PlatformSpecific-macOS.swift 888B
AttributedString.swift 640B
SavePanelAccessoryViewController.swift 583B
AppDelegate.swift 513B
共 114 条
- 1
- 2
资源评论
小菜的OnePiece
- 粉丝: 105
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功