Merge branch 'master' into master
This commit is contained in:
commit
8fb566963b
19
col.go
19
col.go
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/extrame/goyymmdd"
|
yymmdd "github.com/extrame/goyymmdd"
|
||||||
)
|
)
|
||||||
|
|
||||||
//content type
|
//content type
|
||||||
@ -72,7 +72,6 @@ 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 yymmdd.Format(t, formatter.str)
|
return yymmdd.Format(t, formatter.str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,9 +168,25 @@ type NumberCol struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *NumberCol) String(wb *WorkBook) []string {
|
func (c *NumberCol) String(wb *WorkBook) []string {
|
||||||
|
if fNo := wb.Xfs[c.Index].formatNo(); fNo != 0 {
|
||||||
|
t := timeFromExcelTime(c.Float, wb.dateMode == 1)
|
||||||
|
return []string{yymmdd.Format(t, wb.Formats[fNo].str)}
|
||||||
|
}
|
||||||
return []string{strconv.FormatFloat(c.Float, 'f', -1, 64)}
|
return []string{strconv.FormatFloat(c.Float, 'f', -1, 64)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FormulaStringCol struct {
|
||||||
|
Col
|
||||||
|
RenderedValue string
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
type FormulaCol struct {
|
type FormulaCol struct {
|
||||||
Header struct {
|
Header struct {
|
||||||
Col
|
Col
|
||||||
|
11
row.go
11
row.go
@ -35,6 +35,17 @@ func (r *Row) Col(i int) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ColExact Get the Nth Col from the Row, if has not, return nil.
|
||||||
|
//For merged cells value is returned for first cell only
|
||||||
|
func (r *Row) ColExact(i int) string {
|
||||||
|
serial := uint16(i)
|
||||||
|
if ch, ok := r.cols[serial]; ok {
|
||||||
|
strs := ch.String(r.wb)
|
||||||
|
return strs[0]
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
//LastCol Get the number of Last Col of the Row.
|
//LastCol Get the number of Last Col of the Row.
|
||||||
func (r *Row) LastCol() int {
|
func (r *Row) LastCol() int {
|
||||||
return int(r.info.Lcell)
|
return int(r.info.Lcell)
|
||||||
|
@ -255,7 +255,7 @@ func (w *WorkBook) get_string(buf io.ReadSeeker, size uint16) (res string, err e
|
|||||||
|
|
||||||
func (w *WorkBook) addSheet(sheet *boundsheet, buf io.ReadSeeker) {
|
func (w *WorkBook) addSheet(sheet *boundsheet, buf io.ReadSeeker) {
|
||||||
name, _ := w.get_string(buf, uint16(sheet.Name))
|
name, _ := w.get_string(buf, uint16(sheet.Name))
|
||||||
w.sheets = append(w.sheets, &WorkSheet{bs: sheet, Name: name, wb: w})
|
w.sheets = append(w.sheets, &WorkSheet{bs: sheet, Name: name, wb: w, Visibility: TWorkSheetVisibility(sheet.Visible)})
|
||||||
}
|
}
|
||||||
|
|
||||||
//reading a sheet from the compress file to memory, you should call this before you try to get anything from sheet
|
//reading a sheet from the compress file to memory, you should call this before you try to get anything from sheet
|
||||||
|
59
worksheet.go
59
worksheet.go
@ -1,28 +1,40 @@
|
|||||||
package xls
|
package xls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"unicode/utf16"
|
"unicode/utf16"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TWorkSheetVisibility byte
|
||||||
|
|
||||||
|
const (
|
||||||
|
WorkSheetVisible TWorkSheetVisibility = 0
|
||||||
|
WorkSheetHidden TWorkSheetVisibility = 1
|
||||||
|
WorkSheetVeryHidden TWorkSheetVisibility = 2
|
||||||
|
)
|
||||||
|
|
||||||
type boundsheet struct {
|
type boundsheet struct {
|
||||||
Filepos uint32
|
Filepos uint32
|
||||||
Type byte
|
|
||||||
Visible byte
|
Visible byte
|
||||||
|
Type byte
|
||||||
Name byte
|
Name byte
|
||||||
}
|
}
|
||||||
|
|
||||||
//WorkSheet in one WorkBook
|
//WorkSheet in one WorkBook
|
||||||
type WorkSheet struct {
|
type WorkSheet struct {
|
||||||
bs *boundsheet
|
bs *boundsheet
|
||||||
wb *WorkBook
|
wb *WorkBook
|
||||||
Name string
|
Name string
|
||||||
rows map[uint16]*Row
|
Selected bool
|
||||||
|
Visibility TWorkSheetVisibility
|
||||||
|
rows map[uint16]*Row
|
||||||
//NOTICE: this is the max row number of the sheet, so it should be count -1
|
//NOTICE: this is the max row number of the sheet, so it should be count -1
|
||||||
MaxRow uint16
|
MaxRow uint16
|
||||||
parsed bool
|
parsed bool
|
||||||
|
rightToLeft bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WorkSheet) Row(i int) *Row {
|
func (w *WorkSheet) Row(i int) *Row {
|
||||||
@ -37,9 +49,10 @@ func (w *WorkSheet) parse(buf io.ReadSeeker) {
|
|||||||
w.rows = make(map[uint16]*Row)
|
w.rows = make(map[uint16]*Row)
|
||||||
b := new(bof)
|
b := new(bof)
|
||||||
var bof_pre *bof
|
var bof_pre *bof
|
||||||
|
var col_pre interface{}
|
||||||
for {
|
for {
|
||||||
if err := binary.Read(buf, binary.LittleEndian, b); err == nil {
|
if err := binary.Read(buf, binary.LittleEndian, b); err == nil {
|
||||||
bof_pre = w.parseBof(buf, b, bof_pre)
|
bof_pre, col_pre = w.parseBof(buf, b, bof_pre, col_pre)
|
||||||
if b.Id == 0xa {
|
if b.Id == 0xa {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -51,11 +64,22 @@ func (w *WorkSheet) parse(buf io.ReadSeeker) {
|
|||||||
w.parsed = true
|
w.parsed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WorkSheet) parseBof(buf io.ReadSeeker, b *bof, pre *bof) *bof {
|
func (w *WorkSheet) parseBof(buf io.ReadSeeker, b *bof, pre *bof, col_pre interface{}) (*bof, interface{}) {
|
||||||
var col interface{}
|
var col interface{}
|
||||||
|
var bts = make([]byte, b.Size)
|
||||||
|
binary.Read(buf, binary.LittleEndian, bts)
|
||||||
|
buf = bytes.NewReader(bts)
|
||||||
switch b.Id {
|
switch b.Id {
|
||||||
// case 0x0E5: //MERGEDCELLS
|
// case 0x0E5: //MERGEDCELLS
|
||||||
// ws.mergedCells(buf)
|
// ws.mergedCells(buf)
|
||||||
|
case 0x23E: // WINDOW2
|
||||||
|
var sheetOptions, firstVisibleRow, firstVisibleColumn uint16
|
||||||
|
binary.Read(buf, binary.LittleEndian, &sheetOptions)
|
||||||
|
binary.Read(buf, binary.LittleEndian, &firstVisibleRow) // not valuable
|
||||||
|
binary.Read(buf, binary.LittleEndian, &firstVisibleColumn) // not valuable
|
||||||
|
//buf.Seek(int64(b.Size)-2*3, 1)
|
||||||
|
w.rightToLeft = (sheetOptions & 0x40) != 0
|
||||||
|
w.Selected = (sheetOptions & 0x400) != 0
|
||||||
case 0x208: //ROW
|
case 0x208: //ROW
|
||||||
r := new(rowInfo)
|
r := new(rowInfo)
|
||||||
binary.Read(buf, binary.LittleEndian, r)
|
binary.Read(buf, binary.LittleEndian, r)
|
||||||
@ -89,6 +113,18 @@ func (w *WorkSheet) parseBof(buf io.ReadSeeker, b *bof, pre *bof) *bof {
|
|||||||
c.Bts = make([]byte, b.Size-20)
|
c.Bts = make([]byte, b.Size-20)
|
||||||
binary.Read(buf, binary.LittleEndian, &c.Bts)
|
binary.Read(buf, binary.LittleEndian, &c.Bts)
|
||||||
col = c
|
col = c
|
||||||
|
case 0x207: //STRING = FORMULA-VALUE is expected right after FORMULA
|
||||||
|
if ch, ok := col_pre.(*FormulaCol); ok {
|
||||||
|
c := new(FormulaStringCol)
|
||||||
|
c.Col = ch.Header.Col
|
||||||
|
var cStringLen uint16
|
||||||
|
binary.Read(buf, binary.LittleEndian, &cStringLen)
|
||||||
|
str, err := w.wb.get_string(buf, cStringLen)
|
||||||
|
if nil == err {
|
||||||
|
c.RenderedValue = str
|
||||||
|
}
|
||||||
|
col = c
|
||||||
|
}
|
||||||
case 0x27e: //RK
|
case 0x27e: //RK
|
||||||
col = new(RkCol)
|
col = new(RkCol)
|
||||||
binary.Read(buf, binary.LittleEndian, col)
|
binary.Read(buf, binary.LittleEndian, col)
|
||||||
@ -163,7 +199,7 @@ func (w *WorkSheet) parseBof(buf io.ReadSeeker, b *bof, pre *bof) *bof {
|
|||||||
if col != nil {
|
if col != nil {
|
||||||
w.add(col)
|
w.add(col)
|
||||||
}
|
}
|
||||||
return b
|
return b, col
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WorkSheet) add(content interface{}) {
|
func (w *WorkSheet) add(content interface{}) {
|
||||||
@ -194,6 +230,9 @@ func (w *WorkSheet) addContent(row_num uint16, ch contentHandler) {
|
|||||||
info.Index = row_num
|
info.Index = row_num
|
||||||
row = w.addRow(info)
|
row = w.addRow(info)
|
||||||
}
|
}
|
||||||
|
if row.info.Lcell < ch.LastCol() {
|
||||||
|
row.info.Lcell = ch.LastCol()
|
||||||
|
}
|
||||||
row.cols[ch.FirstCol()] = ch
|
row.cols[ch.FirstCol()] = ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user