20
0

add file link support

This commit is contained in:
Liu Ming 2015-03-25 11:03:05 +08:00
parent 5544765b84
commit 7345247a91
3 changed files with 51 additions and 29 deletions

20
bof.go
View File

@ -1,12 +1,30 @@
package xls
import ()
import (
"bytes"
"encoding/binary"
"io"
"unicode/utf16"
)
type BOF struct {
Id uint16
Size uint16
}
func (b *BOF) Reader(buf io.ReadSeeker) io.ReadSeeker {
rts := make([]byte, b.Size)
buf.Read(rts)
return bytes.NewReader(rts)
}
func (b *BOF) Utf16String(buf io.ReadSeeker, count uint32) string {
var bts = make([]uint16, count)
binary.Read(buf, binary.LittleEndian, &bts)
runes := utf16.Decode(bts[:len(bts)-1])
return string(runes)
}
type BIFFHeader struct {
Ver uint16
Type uint16

View File

@ -38,22 +38,22 @@ type HyperLink struct {
TextMark string
TargetFrame string
Url string
ShortedFilePath string
ExtendedFilePath string
IsUrl bool
}
func (h *HyperLink) String(wb *WorkBook) []string {
res := make([]string, h.LastColB-h.FristColB+1)
str := fmt.Sprintf("%s(%s)", h.Description, h.Url)
var str string
if h.IsUrl {
str = fmt.Sprintf("%s(%s)", h.Description, h.Url)
} else {
str = h.ExtendedFilePath
}
for i := uint16(0); i < h.LastColB-h.FristColB+1; i++ {
res[i] = str
}
return res
}
// func (h *HyperLinkCR) ParseFrom(buf io.ReadSeeker) {
// if h.Flags&0x1 != 0 {
// binary.Read(buf, binary.LittleEndian, &richtext_num)
// }
// if h.Flags&0x4 != 0 {
// binary.Read(buf, binary.LittleEndian, &phonetic_size)
// }
// }

View File

@ -87,7 +87,6 @@ func (w *WorkSheet) parseBof(buf io.ReadSeeker, bof *BOF, pre *BOF) *BOF {
case 0x1b8: //HYPERLINK
var hy HyperLink
binary.Read(buf, binary.LittleEndian, &hy.CellRange)
buf.Seek(20, 1)
var flag uint32
binary.Read(buf, binary.LittleEndian, &flag)
@ -95,29 +94,34 @@ func (w *WorkSheet) parseBof(buf io.ReadSeeker, bof *BOF, pre *BOF) *BOF {
if flag&0x14 != 0 {
binary.Read(buf, binary.LittleEndian, &count)
var bts = make([]uint16, count)
binary.Read(buf, binary.LittleEndian, &bts)
runes := utf16.Decode(bts[:len(bts)-1])
hy.Description = string(runes)
hy.Description = bof.Utf16String(buf, count)
}
if flag&0x80 != 0 {
binary.Read(buf, binary.LittleEndian, &count)
var bts = make([]uint16, count)
binary.Read(buf, binary.LittleEndian, &bts)
runes := utf16.Decode(bts[:len(bts)-1])
hy.TargetFrame = string(runes)
hy.TargetFrame = bof.Utf16String(buf, count)
}
if flag&0x1 != 0 {
var guid [2]uint64
binary.Read(buf, binary.BigEndian, &guid)
if guid[0] == 0xE0C9EA79F9BACE11 && guid[1] == 0x8C8200AA004BA90B { //URL
hy.IsUrl = true
binary.Read(buf, binary.LittleEndian, &count)
var bts = make([]uint16, count/2)
hy.Url = bof.Utf16String(buf, count/2)
} else if guid[0] == 0x303000000000000 && guid[1] == 0xC000000000000046 { //URL{
var upCount uint16
binary.Read(buf, binary.LittleEndian, &upCount)
binary.Read(buf, binary.LittleEndian, &count)
bts := make([]byte, count)
binary.Read(buf, binary.LittleEndian, &bts)
runes := utf16.Decode(bts[:len(bts)-1])
hy.Url = string(runes)
} else {
log.Panicln("not support yet")
hy.ShortedFilePath = string(bts)
buf.Seek(24, 1)
binary.Read(buf, binary.LittleEndian, &count)
if count > 0 {
binary.Read(buf, binary.LittleEndian, &count)
buf.Seek(2, 1)
hy.ExtendedFilePath = bof.Utf16String(buf, count/2+1)
}
log.Println(hy)
}
}
if flag&0x8 != 0 {