20
0
This commit is contained in:
Liu Ming 2017-02-21 16:59:50 +08:00
parent f02a04cbdd
commit 79987c0cd7
3 changed files with 9 additions and 33 deletions

View File

@ -17,31 +17,5 @@ It has just the reading function without the format.
* Use **Open** function for open file
* Use **OpenReader** function for open xls from a reader
These methods will open a workbook object for reading, like
func (w *WorkBook) ReadAllCells() (res [][]string) {
for _, sheet := range w.Sheets {
w.PrepareSheet(sheet)
if sheet.MaxRow != 0 {
temp := make([][]string, sheet.MaxRow+1)
for k, row := range sheet.Rows {
data := make([]string, 0)
if len(row.Cols) > 0 {
for _, col := range row.Cols {
if uint16(len(data)) <= col.LastCol() {
data = append(data, make([]string, col.LastCol()-uint16(len(data))+1)...)
}
str := col.String(w)
for i := uint16(0); i < col.LastCol()-col.FirstCol()+1; i++ {
data[col.FirstCol()+i] = str[i]
}
}
temp[k] = data
}
}
res = append(res, temp...)
}
}
return
}
* Follow the example in GODOC

View File

@ -115,14 +115,15 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
var size uint16
var i = 0
for ; i < int(info.Count); i++ {
if err := binary.Read(buf_item, binary.LittleEndian, &size); err == nil {
var err error
if err = binary.Read(buf_item, binary.LittleEndian, &size); err == nil {
var str string
str, err = wb.get_string(buf_item, size)
wb.sst[i] = wb.sst[i] + str
}
if err == io.EOF {
break
}
if err == io.EOF {
break
}
}
offset = i

View File

@ -7,10 +7,10 @@ import (
)
func TestOpen(t *testing.T) {
if xlFile, err := Open("expenses.xls", "utf-8"); err == nil {
if xlFile, err := Open("t1.xls", "utf-8"); err == nil {
if sheet1 := xlFile.GetSheet(0); sheet1 != nil {
fmt.Println("Total Lines ", sheet1.MaxRow, sheet1.Name)
for i := 0; i <= int(sheet1.MaxRow); i++ {
for i := 265; i <= 267; i++ {
fmt.Printf("row %v point %v \n", i, sheet1.Row(i))
if sheet1.Row(i) == nil {
continue
@ -18,6 +18,7 @@ func TestOpen(t *testing.T) {
row := sheet1.Row(i)
for index := row.FirstCol(); index < row.LastCol(); index++ {
fmt.Println(index, "==>", row.Col(index), " ")
fmt.Printf("%T\n", row.cols[uint16(index)])
}
// col1 := .Cols[0]
// col2 := sheet1.Row(uint16(i)].Cols[1]