szyhf / go-excel

A simple and light excel file reader to read a standard excel as a table faster | 一个轻量级的Excel数据读取库,用一种更`关系数据库`的方式解析Excel。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sheetName Unable to read properly

tomiaa1926 opened this issue · comments

commented

config Integer default 0 like :

&excel.Config{
		// Sheet name as string or sheet model as object or a slice of object.
		Sheet: 0,
		// Use the index row as title, every row before title-row will be ignore, default is 0.
		TitleRowIndex: 1,
		// Skip n row after title, default is 0 (not skip), empty row is not counted.
		Skip: 0,
		// Auto prefix to sheet name.
		Prefix: "",
		// Auto suffix to sheet name.
		Suffix: "",
	}

error : can not find worksheet named =

try set Sheet to 1

error : runtime error: index out of range [-1]

I have many files and sheetName is different. They all have only one sheet, How to Set the Default Read First?

please try:

// if sheet is int, will i'th sheet in the workbook, be careful the hidden sheet is counted. i ∈ [1,+inf]

if it can't work, try

go-excel/types.go

Lines 46 to 48 in c6186b0

// Get all sheets name
GetSheetNames() []string

to check if it has your sheets.

if sheets returns correct, please upload a demo of your xlsx file.

commented

This may be my problem, my excel title is Chinese

@tomiaa1926 中文应该是没问题的,虽然我这没有拿中文做标题,但是解析内容也很多中文……要不你拿example的表改成中文标题先试试看😓

commented

我是懒得弄了,因为很多表全是制式的标题全是中文,没办法一个个去修改乐。
不过有的表我有试过,可以读取出来。但还是有一些其他的错误
我一开始以为是sheetname的问题,今天看了下并不是
index out of range [-1] 这里提示是MapToFields 方法里的错误
这个表的内容不太标准了 😅

噢,有个比较常见而且不好处理的问题,是有空格子,就是格子看起来没东西,但实际生成了一个空字符串,占了一个格子(而且有可能这个是合法的场景),但这个会影响对配表格式的最终判定(可能符合预期,也可能不符合预期)。

excel底层的原生数据结构不是关系数据库,我这个工具其实是个根据配置和实际底层数据对结构进行推断,然后再按关系数据的逻辑重新组织的。

如果表格确实复杂的话,建议拿https://github.com/qax-os/excelize看看,这个是按excel的原生结构解析配置的工具。

还有个思路就是利用excel本身的导出功能,先把数据导出成json或者csv之类的,自己再处理。

commented

😭 嗯我就切换成这个了按索引取值了,就可以忽略掉出问题的title了