1
0
mirror of https://github.com/pbnjay/grate.git synced 2026-05-16 09:08:09 +02:00

fix XLS merged cells and ensure sentinals are correctly saved

This commit is contained in:
Jeremy Jay
2022-02-25 01:02:28 -05:00
parent a5375a6478
commit e2d22a3b93
3 changed files with 18 additions and 4 deletions
+2
View File
@@ -40,6 +40,8 @@ func (c CellType) String() string {
return "date" return "date"
case HyperlinkStringCell: case HyperlinkStringCell:
return "hyperlink" return "hyperlink"
case StaticCell:
return "static"
default: // StringCell, StaticCell default: // StringCell, StaticCell
return "string" return "string"
} }
+12
View File
@@ -67,6 +67,14 @@ func (s *Sheet) Put(row, col int, value interface{}, fmtNum uint16) {
s.Resize(s.NumRows, s.NumCols) s.Resize(s.NumRows, s.NumCols)
} }
if spec, ok := value.(string); ok {
if spec == grate.EndRowMerged || spec == grate.EndColumnMerged || spec == grate.ContinueRowMerged || spec == grate.ContinueColumnMerged {
s.Rows[row][col] = NewCell(value)
s.Rows[row][col][1] = StaticCell
return
}
}
ct, ok := s.Formatter.getCellType(fmtNum) ct, ok := s.Formatter.getCellType(fmtNum)
if !ok || fmtNum == 0 { if !ok || fmtNum == 0 {
s.Rows[row][col] = NewCell(value) s.Rows[row][col] = NewCell(value)
@@ -125,6 +133,10 @@ func (s *Sheet) Strings() []string {
res[i] = "" res[i] = ""
continue continue
} }
if cell.Type() == StaticCell {
res[i] = cell.Value().(string)
continue
}
val := cell.Value() val := cell.Value()
fs, ok := s.Formatter.Apply(cell.FormatNo(), val) fs, ok := s.Formatter.Apply(cell.FormatNo(), val)
if !ok { if !ok {
+4 -4
View File
@@ -386,10 +386,10 @@ func (b *WorkBook) parseSheet(s *boundSheet, ss int) (*commonxl.Sheet, error) {
cmcs := binary.LittleEndian.Uint16(r.Data[:2]) cmcs := binary.LittleEndian.Uint16(r.Data[:2])
raw := r.Data[2:] raw := r.Data[2:]
for i := 0; i < int(cmcs); i++ { for i := 0; i < int(cmcs); i++ {
firstRow := binary.LittleEndian.Uint16(r.Data[:2]) firstRow := binary.LittleEndian.Uint16(raw[:2])
lastRow := binary.LittleEndian.Uint16(r.Data[2:4]) lastRow := binary.LittleEndian.Uint16(raw[2:4])
firstCol := binary.LittleEndian.Uint16(r.Data[4:6]) firstCol := binary.LittleEndian.Uint16(raw[4:6])
lastCol := binary.LittleEndian.Uint16(r.Data[6:]) lastCol := binary.LittleEndian.Uint16(raw[6:])
raw = raw[8:] raw = raw[8:]
if lastRow == 0xFFFF { // placeholder value indicate "last" if lastRow == 0xFFFF { // placeholder value indicate "last"