20
0

fix:add parse merge cell

This commit is contained in:
吴俊杰 2020-09-11 14:25:20 +08:00
parent 4a6cf26307
commit 03cbf97453
3 changed files with 34 additions and 7 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea/
go.sum

22
col.go
View File

@ -11,7 +11,7 @@ import (
yymmdd "github.com/extrame/goyymmdd" yymmdd "github.com/extrame/goyymmdd"
) )
//content type // content type
type contentHandler interface { type contentHandler interface {
String(*WorkBook) []string String(*WorkBook) []string
FirstCol() uint16 FirstCol() uint16
@ -64,7 +64,7 @@ func (xf *XfRk) String(wb *WorkBook) string {
strings.Contains(formatterLower, "d.y") || strings.Contains(formatterLower, "d.y") ||
strings.Contains(formatterLower, "h:") || strings.Contains(formatterLower, "h:") ||
strings.Contains(formatterLower, "д.г") { strings.Contains(formatterLower, "д.г") {
//If format contains # or .00 then this is a number // If format contains # or .00 then this is a number
return xf.Rk.String() return xf.Rk.String()
} else { } else {
i, f, isFloat := xf.Rk.number() i, f, isFloat := xf.Rk.number()
@ -82,7 +82,7 @@ func (xf *XfRk) String(wb *WorkBook) string {
f = float64(i) f = float64(i)
} }
t := timeFromExcelTime(f, wb.dateMode == 1) t := timeFromExcelTime(f, wb.dateMode == 1)
return t.Format(time.RFC3339) //TODO it should be international return t.Format(time.RFC3339) // TODO it should be international
} }
} }
return xf.Rk.String() return xf.Rk.String()
@ -184,8 +184,8 @@ func (c *FormulaStringCol) String(wb *WorkBook) []string {
return []string{c.RenderedValue} return []string{c.RenderedValue}
} }
//str, err = wb.get_string(buf_item, size) // str, err = wb.get_string(buf_item, size)
//wb.sst[offset_pre] = wb.sst[offset_pre] + str // wb.sst[offset_pre] = wb.sst[offset_pre] + str
type FormulaCol struct { type FormulaCol struct {
Header struct { Header struct {
@ -238,3 +238,15 @@ type BlankCol struct {
func (c *BlankCol) String(wb *WorkBook) []string { func (c *BlankCol) String(wb *WorkBook) []string {
return []string{""} return []string{""}
} }
type MergeCells struct {
Count uint16
Refs []Ref8
}
type Ref8 struct {
RwFirst uint16
RwLast uint16
ColFirst uint16
ColLast uint16
}

View File

@ -5,6 +5,7 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io" "io"
"log"
"unicode/utf16" "unicode/utf16"
) )
@ -35,6 +36,8 @@ type WorkSheet struct {
MaxRow uint16 MaxRow uint16
parsed bool parsed bool
rightToLeft bool rightToLeft bool
// NOTICE: get all merge cell
mergeCells *MergeCells
} }
func (w *WorkSheet) Row(i int) *Row { func (w *WorkSheet) Row(i int) *Row {
@ -70,8 +73,18 @@ func (w *WorkSheet) parseBof(buf io.ReadSeeker, b *bof, pre *bof, col_pre interf
binary.Read(buf, binary.LittleEndian, bts) binary.Read(buf, binary.LittleEndian, bts)
buf = bytes.NewReader(bts) buf = bytes.NewReader(bts)
switch b.Id { switch b.Id {
// case 0x0E5: //MERGEDCELLS case 0x0E5: // MERGEDCELLS
// ws.mergedCells(buf) mergeCells := new(MergeCells)
err := binary.Read(buf, binary.LittleEndian, &mergeCells.Count)
size := (b.Size - 2) / 8
mergeCells.Refs = make([]Ref8, size)
for i := uint16(0); i < size; i++ {
binary.Read(buf, binary.LittleEndian, &mergeCells.Refs[i])
}
if err != nil {
log.Fatal(err)
}
w.mergeCells = mergeCells
case 0x23E: // WINDOW2 case 0x23E: // WINDOW2
var sheetOptions, firstVisibleRow, firstVisibleColumn uint16 var sheetOptions, firstVisibleRow, firstVisibleColumn uint16
binary.Read(buf, binary.LittleEndian, &sheetOptions) binary.Read(buf, binary.LittleEndian, &sheetOptions)