🎨 Refactored XML generation logic and fixed content type override issues
This commit is contained in:
@@ -40,7 +40,6 @@ func NewContentTypes() *ContentTypes {
|
||||
ct.AddOverride("/xl/workbook.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")
|
||||
ct.AddOverride("/xl/styles.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml")
|
||||
ct.AddOverride("/xl/theme/theme1.xml", "application/vnd.openxmlformats-officedocument.theme+xml")
|
||||
ct.AddOverride("/xl/worksheets/sheet1.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml")
|
||||
ct.AddOverride("/xl/sharedStrings.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml")
|
||||
|
||||
return ct
|
||||
|
@@ -259,7 +259,7 @@ func main() {
|
||||
})
|
||||
|
||||
// 保存Excel文件
|
||||
err := wb.Save("sales_report.xlsx")
|
||||
err := wb.Save("./workbook/examples/simple/sales_report.xlsx")
|
||||
if err != nil {
|
||||
fmt.Println("保存Excel文件时出错:", err)
|
||||
return
|
||||
|
@@ -71,6 +71,11 @@ func (wb *Workbook) Save(filename string) error {
|
||||
zipWriter := zip.NewWriter(file)
|
||||
defer zipWriter.Close()
|
||||
|
||||
// 为每个工作表添加内容类型覆盖
|
||||
for i := range wb.Worksheets {
|
||||
wb.ContentTypes.AddWorksheetOverride(i + 1)
|
||||
}
|
||||
|
||||
// 添加[Content_Types].xml
|
||||
contentTypesWriter, err := zipWriter.Create("[Content_Types].xml")
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user