Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:add parse merge cell #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
go.sum
22 changes: 17 additions & 5 deletions col.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
yymmdd "github.com/extrame/goyymmdd"
)

//content type
// content type
type contentHandler interface {
String(*WorkBook) []string
FirstCol() uint16
Expand Down Expand Up @@ -64,7 +64,7 @@ func (xf *XfRk) String(wb *WorkBook) string {
strings.Contains(formatterLower, "d.y") ||
strings.Contains(formatterLower, "h:") ||
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()
} else {
i, f, isFloat := xf.Rk.number()
Expand All @@ -82,7 +82,7 @@ func (xf *XfRk) String(wb *WorkBook) string {
f = float64(i)
}
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()
Expand Down Expand Up @@ -184,8 +184,8 @@ func (c *FormulaStringCol) String(wb *WorkBook) []string {
return []string{c.RenderedValue}
}

//str, err = wb.get_string(buf_item, size)
//wb.sst[offset_pre] = wb.sst[offset_pre] + str
// str, err = wb.get_string(buf_item, size)
// wb.sst[offset_pre] = wb.sst[offset_pre] + str

type FormulaCol struct {
Header struct {
Expand Down Expand Up @@ -238,3 +238,15 @@ type BlankCol struct {
func (c *BlankCol) String(wb *WorkBook) []string {
return []string{""}
}

type MergeCells struct {
Count uint16
Refs []Ref8
}

type Ref8 struct {
RwFirst uint16
RwLast uint16
ColFirst uint16
ColLast uint16
}
17 changes: 15 additions & 2 deletions worksheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"fmt"
"io"
"log"
"unicode/utf16"
)

Expand Down Expand Up @@ -35,6 +36,8 @@ type WorkSheet struct {
MaxRow uint16
parsed bool
rightToLeft bool
// NOTICE: get all merge cell
mergeCells *MergeCells
}

func (w *WorkSheet) Row(i int) *Row {
Expand Down Expand Up @@ -70,8 +73,18 @@ func (w *WorkSheet) parseBof(buf io.ReadSeeker, b *bof, pre *bof, col_pre interf
binary.Read(buf, binary.LittleEndian, bts)
buf = bytes.NewReader(bts)
switch b.Id {
// case 0x0E5: //MERGEDCELLS
// ws.mergedCells(buf)
case 0x0E5: // MERGEDCELLS
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
var sheetOptions, firstVisibleRow, firstVisibleColumn uint16
binary.Read(buf, binary.LittleEndian, &sheetOptions)
Expand Down