已验证 提交 f91f5486 编写于 作者: xurime's avatar xurime

Resolve #404, get sheet map by target rels.

上级 7e77e148
......@@ -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
}
......
......@@ -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
}
......@@ -1950,7 +1947,7 @@ 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
......@@ -1958,7 +1955,7 @@ func setFont(formatStyle *formatStyle) *font {
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},
......
......@@ -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"`
......@@ -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
......@@ -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"`
......
......@@ -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"`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册