Skip to content

Commit

Permalink
Resolve qax-os#404, get sheet map by target rels.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed May 17, 2019
1 parent 45b02c7 commit 8b1ef6c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
16 changes: 11 additions & 5 deletions sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,18 @@ func (f *File) GetSheetMap() map[int]string {
return sheetMap
}

// getSheetMap provides a function to get worksheet name and XML file path map of
// XLSX.
// getSheetMap provides a function to get worksheet name and XML file path map
// of XLSX.
func (f *File) getSheetMap() map[string]string {
maps := make(map[string]string)
for idx, name := range f.GetSheetMap() {
maps[name] = "xl/worksheets/sheet" + strconv.Itoa(idx) + ".xml"
content := f.workbookReader()
rels := f.workbookRelsReader()
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
}
Expand Down
9 changes: 3 additions & 6 deletions styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -1895,11 +1895,8 @@ func (f *File) NewStyle(style string) (int, error) {
numFmtID := setNumFmt(s, fs)

if fs.Font != nil {
font, _ := xml.Marshal(setFont(fs))
s.Fonts.Count++
s.Fonts.Font = append(s.Fonts.Font, &xlsxFont{
Font: string(font[6 : len(font)-7]),
})
s.Fonts.Font = append(s.Fonts.Font, setFont(fs))
fontID = s.Fonts.Count - 1
}

Expand Down Expand Up @@ -1950,15 +1947,15 @@ func (f *File) NewConditionalStyle(style string) (int, error) {

// setFont provides a function to add font style by given cell format
// settings.
func setFont(formatStyle *formatStyle) *font {
func setFont(formatStyle *formatStyle) *xlsxFont {
fontUnderlineType := map[string]string{"single": "single", "double": "double"}
if formatStyle.Font.Size < 1 {
formatStyle.Font.Size = 11
}
if formatStyle.Font.Color == "" {
formatStyle.Font.Color = "#000000"
}
f := font{
f := xlsxFont{
B: formatStyle.Font.Bold,
I: formatStyle.Font.Italic,
Sz: &attrValInt{Val: formatStyle.Font.Size},
Expand Down
13 changes: 4 additions & 9 deletions xmlStyles.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ type xlsxFonts struct {
Font []*xlsxFont `xml:"font"`
}

// font directly maps the font element.
type font struct {
// xlsxFont directly maps the font element. This element defines the
// properties for one of the fonts used in this workbook.
type xlsxFont struct {
Name *attrValString `xml:"name"`
Charset *attrValInt `xml:"charset"`
Family *attrValInt `xml:"family"`
Expand All @@ -100,12 +101,6 @@ type font struct {
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
// 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
Expand Down Expand Up @@ -262,7 +257,7 @@ type xlsxDxf struct {

// dxf directly maps the dxf element.
type dxf struct {
Font *font `xml:"font"`
Font *xlsxFont `xml:"font"`
NumFmt *xlsxNumFmt `xml:"numFmt"`
Fill *xlsxFill `xml:"fill"`
Alignment *xlsxAlignment `xml:"alignment"`
Expand Down
5 changes: 2 additions & 3 deletions xmlWorkbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ type xlsxSheets struct {
Sheet []xlsxSheet `xml:"sheet"`
}

// xlsxSheet directly maps the sheet element from the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
// xlsxSheet defines a sheet in this workbook. Sheet data is stored in a
// separate part.
type xlsxSheet struct {
Name string `xml:"name,attr,omitempty"`
SheetID int `xml:"sheetId,attr,omitempty"`
Expand Down

0 comments on commit 8b1ef6c

Please sign in to comment.