Resolve #404, get sheet map by target rels.
This commit is contained in:
parent
7e77e14814
commit
f91f548614
16
sheet.go
16
sheet.go
|
@ -369,12 +369,18 @@ func (f *File) GetSheetMap() map[int]string {
|
||||||
return sheetMap
|
return sheetMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSheetMap provides a function to get worksheet name and XML file path map of
|
// getSheetMap provides a function to get worksheet name and XML file path map
|
||||||
// XLSX.
|
// of XLSX.
|
||||||
func (f *File) getSheetMap() map[string]string {
|
func (f *File) getSheetMap() map[string]string {
|
||||||
maps := make(map[string]string)
|
content := f.workbookReader()
|
||||||
for idx, name := range f.GetSheetMap() {
|
rels := f.workbookRelsReader()
|
||||||
maps[name] = "xl/worksheets/sheet" + strconv.Itoa(idx) + ".xml"
|
maps := map[string]string{}
|
||||||
|
for _, v := range content.Sheets.Sheet {
|
||||||
|
for _, rel := range rels.Relationships {
|
||||||
|
if rel.ID == v.ID {
|
||||||
|
maps[v.Name] = fmt.Sprintf("xl/%s", rel.Target)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return maps
|
return maps
|
||||||
}
|
}
|
||||||
|
|
|
@ -1895,11 +1895,8 @@ func (f *File) NewStyle(style string) (int, error) {
|
||||||
numFmtID := setNumFmt(s, fs)
|
numFmtID := setNumFmt(s, fs)
|
||||||
|
|
||||||
if fs.Font != nil {
|
if fs.Font != nil {
|
||||||
font, _ := xml.Marshal(setFont(fs))
|
|
||||||
s.Fonts.Count++
|
s.Fonts.Count++
|
||||||
s.Fonts.Font = append(s.Fonts.Font, &xlsxFont{
|
s.Fonts.Font = append(s.Fonts.Font, setFont(fs))
|
||||||
Font: string(font[6 : len(font)-7]),
|
|
||||||
})
|
|
||||||
fontID = s.Fonts.Count - 1
|
fontID = s.Fonts.Count - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1950,7 +1947,7 @@ func (f *File) NewConditionalStyle(style string) (int, error) {
|
||||||
|
|
||||||
// setFont provides a function to add font style by given cell format
|
// setFont provides a function to add font style by given cell format
|
||||||
// settings.
|
// settings.
|
||||||
func setFont(formatStyle *formatStyle) *font {
|
func setFont(formatStyle *formatStyle) *xlsxFont {
|
||||||
fontUnderlineType := map[string]string{"single": "single", "double": "double"}
|
fontUnderlineType := map[string]string{"single": "single", "double": "double"}
|
||||||
if formatStyle.Font.Size < 1 {
|
if formatStyle.Font.Size < 1 {
|
||||||
formatStyle.Font.Size = 11
|
formatStyle.Font.Size = 11
|
||||||
|
@ -1958,7 +1955,7 @@ func setFont(formatStyle *formatStyle) *font {
|
||||||
if formatStyle.Font.Color == "" {
|
if formatStyle.Font.Color == "" {
|
||||||
formatStyle.Font.Color = "#000000"
|
formatStyle.Font.Color = "#000000"
|
||||||
}
|
}
|
||||||
f := font{
|
f := xlsxFont{
|
||||||
B: formatStyle.Font.Bold,
|
B: formatStyle.Font.Bold,
|
||||||
I: formatStyle.Font.Italic,
|
I: formatStyle.Font.Italic,
|
||||||
Sz: &attrValInt{Val: formatStyle.Font.Size},
|
Sz: &attrValInt{Val: formatStyle.Font.Size},
|
||||||
|
|
13
xmlStyles.go
13
xmlStyles.go
|
@ -82,8 +82,9 @@ type xlsxFonts struct {
|
||||||
Font []*xlsxFont `xml:"font"`
|
Font []*xlsxFont `xml:"font"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// font directly maps the font element.
|
// xlsxFont directly maps the font element. This element defines the
|
||||||
type font struct {
|
// properties for one of the fonts used in this workbook.
|
||||||
|
type xlsxFont struct {
|
||||||
Name *attrValString `xml:"name"`
|
Name *attrValString `xml:"name"`
|
||||||
Charset *attrValInt `xml:"charset"`
|
Charset *attrValInt `xml:"charset"`
|
||||||
Family *attrValInt `xml:"family"`
|
Family *attrValInt `xml:"family"`
|
||||||
|
@ -100,12 +101,6 @@ type font struct {
|
||||||
Scheme *attrValString `xml:"scheme"`
|
Scheme *attrValString `xml:"scheme"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// xlsxFont directly maps the font element. This element defines the properties
|
|
||||||
// for one of the fonts used in this workbook.
|
|
||||||
type xlsxFont struct {
|
|
||||||
Font string `xml:",innerxml"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// xlsxFills directly maps the fills element. This element defines the cell
|
// xlsxFills directly maps the fills element. This element defines the cell
|
||||||
// fills portion of the Styles part, consisting of a sequence of fill records. A
|
// fills portion of the Styles part, consisting of a sequence of fill records. A
|
||||||
// cell fill consists of a background color, foreground color, and pattern to be
|
// cell fill consists of a background color, foreground color, and pattern to be
|
||||||
|
@ -262,7 +257,7 @@ type xlsxDxf struct {
|
||||||
|
|
||||||
// dxf directly maps the dxf element.
|
// dxf directly maps the dxf element.
|
||||||
type dxf struct {
|
type dxf struct {
|
||||||
Font *font `xml:"font"`
|
Font *xlsxFont `xml:"font"`
|
||||||
NumFmt *xlsxNumFmt `xml:"numFmt"`
|
NumFmt *xlsxNumFmt `xml:"numFmt"`
|
||||||
Fill *xlsxFill `xml:"fill"`
|
Fill *xlsxFill `xml:"fill"`
|
||||||
Alignment *xlsxAlignment `xml:"alignment"`
|
Alignment *xlsxAlignment `xml:"alignment"`
|
||||||
|
|
|
@ -146,9 +146,8 @@ type xlsxSheets struct {
|
||||||
Sheet []xlsxSheet `xml:"sheet"`
|
Sheet []xlsxSheet `xml:"sheet"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// xlsxSheet directly maps the sheet element from the namespace
|
// xlsxSheet defines a sheet in this workbook. Sheet data is stored in a
|
||||||
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
|
// separate part.
|
||||||
// not checked it for completeness - it does as much as I need.
|
|
||||||
type xlsxSheet struct {
|
type xlsxSheet struct {
|
||||||
Name string `xml:"name,attr,omitempty"`
|
Name string `xml:"name,attr,omitempty"`
|
||||||
SheetID int `xml:"sheetId,attr,omitempty"`
|
SheetID int `xml:"sheetId,attr,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue