go读取docx文件

主要使用 baliance.com/gooxml 下的 document 包
原理:windows下的docx格式文件实际上是一个压缩包,打开之后可以看到具体的内容
下边直接上代码,实现的是获取docx文件中的文本和表格中的文本

package main
import (
	"fmt"
	"runtime"
	"time"

	"baliance.com/gooxml/document"
)

func main() {
	doc, err := document.Open("测试.docx")
	if err != nil {
		log.Fatalf("error opening document: %s", err)
		return
	}
	//批注
	for _, docfile := range doc.DocBase.ExtraFiles {
		if docfile.ZipPath != "word/comments.xml" {
			continue
		}

		file, err := os.Open(docfile.DiskPath)
		if err != nil {
			continue
		}
		defer file.Close()
		f, err := file.Stat()
		if err != nil {
			continue
		}
		size := f.Size()
		var fileinfo []byte = make([]byte, size)
		_, err = file.Read(fileinfo)
		if err != nil {
			continue
		}
		//实际应该解析<w:t>中的数据
		fmt.Println(string(fileinfo))
	}

	//书签
	for _, bookmark := range doc.Bookmarks() {
		bookname := bookmark.Name()
		if len(bookname) == 0 {
			continue
		}
		fmt.Println(bookmark.Name())
	}

	//页眉
	for _, head := range doc.Headers() {
		var text string
		for _, para := range head.Paragraphs() {
			for _, run := range para.Runs() {
				text += run.Text()
			}
		}
		if len(text) == 0 {
			continue
		}
		fmt.Println(text)
	}

	//页脚
	for _, footer := range doc.Footers() {
		for _, para := range footer.Paragraphs() {
			var text string
			for _, run := range para.Runs() {
				text += run.Text()
			}
			if len(text) == 0 {
				continue
			}
			fmt.Println(text)
		}
	}

	//doc.Paragraphs()得到包含文档所有的段落的切片
	for _, para := range doc.Paragraphs() {
		var text string
		//run为每个段落相同格式的文字组成的片段
		for _, run := range para.Runs() {
			text += run.Text()
		}
		if len(text) == 0 {
			continue
		}
		//打印一段
		fmt.Println(text)
	}

	//获取表格中的文本
	for _, table := range doc.Tables() {
		for _, run := range table.Rows() {
			for _, cell := range run.Cells() {
				var text string
				for _, para := range cell.Paragraphs() {
					for _, run := range para.Runs() {
						//fmt.Print("\t-----------第", j, "格式片段-------------")
						text += run.Text()
					}
				}
				if len(text) == 0 {
					continue
				}
				fmt.Println(text)
			}
		}
	}
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
第01章 课程介绍 1-1 导学.mp4 1-2 课程介绍.mp4 第02章 实战-“云存储”系统原型 2-1 “云存储”系统原型之简单文件上传服务架构说明.mp4 2-2 编码实战:“云存储”系统之实现上传接口.mp4 2-3 编码实战:“云存储”系统之保存文件元信息.mp4 2-4 编码实战:“云存储‘系统之实现单个文件查询信息接口.mp4 2-5 编码实战:“云存储”系统之实现文件下载接口.mp4 2-6 编码实战:“云存储”系统之实现文件修改接口+小结.mp4 第03章 “云存储”系统之基于MySQL实现的文件数据库 3-1 MySQL基础知识.mp4 3-2 MySQL主从数据同步演示.mp4 3-3 文件表的设计及创建.mp4 3-4 编码实战:“云存储”系统之持久化元数据到文件表.mp4 3-5 编码实战:“云存储”系统之从文件表中获取元数据.mp4 3-6 Docker入门基础文档.mp4 3-6 本章小结.mp4 3-7 Ubuntu中通过Docker安装配置MySQL主从节点.mp4 第04章 “云存储”系统之基于用户系统实现的资源隔离及鉴权 4-1 帐号系统介绍与用户表设计.mp4 4-2 编码实战:“云存储”系统之实现用户注册接口.mp4 4-3 编码实战:“云存储”系统之实现用户登录接口.mp4 4-4 编码实战:“云存储”系统之实现用户信息查询接口.mp4 4-5 接口梳理小结.mp4 4-6 编码实战:“云存储”系统之快速实现访问鉴权接口+小结.mp4 4-7 关于静态资源访问404的问题【补漏.mp4 第05章 “云存储”系统之基于Hash计算实现秒传 5-1 Hash算法对比及秒传原理.mp4 5-2 用户文件表设计与创建.mp4 5-3 编码实战:“云存储”系统之升级改造上传接口.mp4 5-4 编码实战:“云存储”系统之基于用户查询文件Hash信息.mp4 5-5 编码实战:“云存储”系统之实现秒传功能接口+小结.mp4 第06章 “云存储”系统之基于Redis实现分块上传及断点续传 6-1_分块上传与断点续传原理.mp4 6-2_编码实战:Go实现Redis连接池(存储分块信息).mp4 6-3_编码实战:实现初始化分块上传接口.mp4 6-4_编码实战:实现分块上传接口.mp4 6-5_编码实战:实现分块合并接口.mp4 6-6_分块上传场景测试+小结.mp4 6-7_文件断点下载原理.mp4 第07章 “云存储”系统之基于Ceph实现私有云存储服务 7-1_Ceph是什么.mp4 7-2_Ceph集群介绍及兼容亚马逊S3接口详解.mp4 7-3_编码实战:Go访问管理Ceph集群.mp4 7-4_编码实战:Go实现Ceph的文件上传下载+小结.mp4 7-5_Ubuntu下通过Docker快速搭建Ceph测试集群(单机部署).mp4 7-6_Centos7下Docker部署Ceph集群(nautilus最新版,多机部署).mp4 第08章 “云存储”系统之基于阿里云OSS实现海量数据上云 8-1_阿里云对象存储OSS简介.mp4 8-2_阿里云对象存储OSS特点.mp4 8-3_阿里云对象存储OSS专业术语.mp4 8-4_阿里云对象存储OSS控制台管理.mp4 8-5_编码实战:OSS上传文件.mp4 8-6_编码实战:OSS下载文件.mp4 8-7_编码实战:OSS对象生命周期管理等常用功能.mp4 8-8_阿里云OSS本章小结.mp4 第09章 “云存储”系统之基于RabbitMQ实现异步存储 9-1_Ubuntu下通过Docker安装RabbitMQ.mp4 9-2_关于任务的同步与异步.mp4 9-3_RabbitMQ简介.mp4 9-4_RabbitMQ工作原理和转发模式.mp4 9-5_Docker安装RabbitMQ及UI管理.mp4 9-6_编码实战_实现异步转移的MQ生产者.mp4 9-7_编码实战_实现异步转移的MQ消费者.mp4 9-8_编码实战_异步转移文件测试+小结.mp4 第10章 “云存储”系统之架构微服务化 10-1_基于Docker部署服务注册发现中心consul集群.mp4 10-2_微服务基础概念与原理.mp4 10-3_云存储系统之微服务架构(1).mp4 10-4_云存储系统之微服务架构(2).mp4 10-5_Web框架Gin基础介绍.mp4 10-6_编码实战_基于Gin改造用户service(1).mp4 10-7_编码实战_基于Gin改造用户service(2.mp4 10-8_gRPC与Protobuf基础原理.mp4 10-9_RPC框架go-micro基础介绍.mp4 10-10_编码实战_改造账号系统service.mp4 10-11_编码实战_改造api网关service.mp4 10-12_编码实战_改造文件上传service.mp4 10-13_综合测试演示+小结.mp4 第11章 “云存储”系统之k8s&Docker;容器化实战 11-1_Ubuntu18下通过kubeadm单机安装k8s(v1.14.1)集群.mp4 11-2_Ubuntu18下安装k8s(v1.14.1)可视化管理工具.mp4 11-3_Docker与Docker-Compose基础概念.mp4 11-4_基于容器的微服务反向代理利器Traefik.mp4 11-5_基于Docker-compose与Traefik的容器化部署演示.mp4 11-6_Kubernetes基础原理.mp4 11-7_基于Kubernetes的容器化部署演示.mp4 第12章 “云存储”系统之持续集成部署 12-1_ubuntu下离线安装harbor1.6.mp4 12-2_持续构建之基础概念.mp4 12-3_基于gitlab+jenkins+harbor的自动化部署配置演示.mp4 第13章 课程总结 13-1_课程总结之章节重点及技能树温习.mp4
官方下载到的go module文档 Table of Contents The "Quick Start" and "New Concepts" sections are particularly important for someone who is starting to work with modules. The "How to..." sections cover more details on mechanics. The largest quantity of content on this page is in the FAQs answering more specific questions; it can be worthwhile to at least skim the FAQ one-liners listed here. Quick Start Example Daily Workflow New Concepts Modules go.mod Version Selection Semantic Import Versioning How to Use Modules How to Install and Activate Module Support How to Define a Module How to Upgrade and Downgrade Dependencies How to Prepare for a Release (All Versions) How to Prepare for a Release (v2 or Higher) Publishing a Release Migrating to Modules Additional Resources Changes Since the Initial Vgo Proposal GitHub Issues FAQs How are versions marked as incompatible? When do I get old behavior vs. new module-based behavior? Why does installing a tool via 'go get' fail with error 'cannot find main module'? How can I track tool dependencies for a module? What is the status of module support in IDEs, editors and standard tools like goimports, gorename, etc.? FAQs — Additional Control What community tooling exists for working with modules? When should I use the 'replace' directive? Can I work entirely outside of VCS on my local filesystem? How do I use vendoring with modules? Is vendoring going away? Are there "always on" module repositories and enterprise proxies? Can I control when go.mod gets updated and when the go tools use the network to satisfy dependencies? How do I use modules with CI systems such as Travis or CircleCI? How do I download modules needed to build specific packages or tests? FAQs — go.mod and go.sum Why does 'go mod tidy' record indirect and test dependencies in my 'go.mod'? Is 'go.sum' a lock file? Why does 'go.sum' include information for module versions I am no longer using? Should I still add a 'go.mod' file if I do not have any dependencies? Should I commit my 'go.sum' file as well as my 'go.mod' file? FAQs — Semantic Import Versioning Why must major version numbers appear in import paths? Why are major versions v0, v1 omitted from import paths? What are some implications of tagging my project with major version v0, v1, or making breaking changes with v2+? Can a module consume a package that has not opted in to modules? Can a module consume a v2+ package that has not opted into modules? What does '+incompatible' mean? How are v2+ modules treated in a build if modules support is not enabled? How does "minimal module compatibility" work in 1.9.7+, 1.10.3+, and 1.11? What happens if I create a go.mod but do not apply semver tags to my repository? Can a module depend on a different version of itself? FAQs — Multi-Module Repositories What are multi-module repositories? Should I have multiple modules in a single repository? Is it possible to add a module to a multi-module repository? Is it possible to remove a module from a multi-module repository? Can a module depend on an internal/ in another? Can an additional go.mod exclude unnecessary content? Do modules have the equivalent of a .gitignore file? FAQs — Minimal Version Selection Won't minimal version selection keep developers from getting important updates? FAQs — Possible Problems What are some general things I can spot check if I am seeing a problem? What can I check if I am not seeing the expected version of a dependency? Why am I getting an error 'cannot find module providing package foo'? Why does 'go mod init' give the error 'cannot determine module path for source directory'? I have a problem with a complex dependency that has not opted in to modules. Can I use information from its current dependency manager? How can I resolve "parsing go.mod: unexpected module path" and "error loading module requirements" errors caused by a mismatch between import paths vs. declared module identity? Why does 'go build' require gcc, and why are prebuilt packages such as net/http not used? Do modules work with relative imports like import "./subdir"? Some needed files may not be present in populated vendor directory

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值