From 1f69f6b24af45bcaa0e9cf1ea6f5426ad3756e87 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 5 Feb 2023 00:21:23 +0800 Subject: [PATCH] Add support for insert BMP format images - Add support for workbook function groups - Update code and docs for the build-in currency number format - Update unit tests --- picture.go | 9 ++++---- picture_test.go | 2 ++ sheet.go | 6 ++--- sheet_test.go | 5 ++++- styles.go | 50 +++++++++++++++++++++--------------------- test/images/excel.bmp | Bin 0 -> 26678 bytes xmlDrawing.go | 6 ++--- xmlWorkbook.go | 13 ++++++++++- 8 files changed, 54 insertions(+), 37 deletions(-) create mode 100755 test/images/excel.bmp diff --git a/picture.go b/picture.go index 067f1bf..f003852 100644 --- a/picture.go +++ b/picture.go @@ -51,8 +51,8 @@ func parseGraphicOptions(opts *GraphicOptions) *GraphicOptions { // AddPicture provides the method to add picture in a sheet by given picture // format set (such as offset, scale, aspect ratio setting and print settings) -// and file path, supported image types: EMF, EMZ, GIF, JPEG, JPG, PNG, SVG, -// TIF, TIFF, WMF, and WMZ. This function is concurrency safe. For example: +// and file path, supported image types: BMP, EMF, EMZ, GIF, JPEG, JPG, PNG, +// SVG, TIF, TIFF, WMF, and WMZ. This function is concurrency safe. For example: // // package main // @@ -436,8 +436,9 @@ func (f *File) addMedia(file []byte, ext string) string { // type for relationship parts and the Main Document part. func (f *File) setContentTypePartImageExtensions() error { imageTypes := map[string]string{ - "jpeg": "image/", "png": "image/", "gif": "image/", "svg": "image/", "tiff": "image/", - "emf": "image/x-", "wmf": "image/x-", "emz": "image/x-", "wmz": "image/x-", + "bmp": "image/", "jpeg": "image/", "png": "image/", "gif": "image/", + "svg": "image/", "tiff": "image/", "emf": "image/x-", "wmf": "image/x-", + "emz": "image/x-", "wmz": "image/x-", } content, err := f.contentTypesReader() if err != nil { diff --git a/picture_test.go b/picture_test.go index eda36ff..d6b91c7 100644 --- a/picture_test.go +++ b/picture_test.go @@ -12,6 +12,7 @@ import ( "strings" "testing" + _ "golang.org/x/image/bmp" _ "golang.org/x/image/tiff" "github.com/stretchr/testify/assert" @@ -64,6 +65,7 @@ func TestAddPicture(t *testing.T) { assert.NoError(t, f.AddPicture("Sheet1", "Q8", filepath.Join("test", "images", "excel.gif"), nil)) assert.NoError(t, f.AddPicture("Sheet1", "Q15", filepath.Join("test", "images", "excel.jpg"), nil)) assert.NoError(t, f.AddPicture("Sheet1", "Q22", filepath.Join("test", "images", "excel.tif"), nil)) + assert.NoError(t, f.AddPicture("Sheet1", "Q28", filepath.Join("test", "images", "excel.bmp"), nil)) // Test write file to given path assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddPicture1.xlsx"))) diff --git a/sheet.go b/sheet.go index 814989a..68cbf50 100644 --- a/sheet.go +++ b/sheet.go @@ -500,8 +500,8 @@ func (f *File) getSheetXMLPath(sheet string) (string, bool) { } // SetSheetBackground provides a function to set background picture by given -// worksheet name and file path. Supported image types: EMF, EMZ, GIF, JPEG, -// JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ. +// worksheet name and file path. Supported image types: BMP, EMF, EMZ, GIF, +// JPEG, JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ. func (f *File) SetSheetBackground(sheet, picture string) error { var err error // Check picture exists first. @@ -514,7 +514,7 @@ func (f *File) SetSheetBackground(sheet, picture string) error { // SetSheetBackgroundFromBytes provides a function to set background picture by // given worksheet name, extension name and image data. Supported image types: -// EMF, EMZ, GIF, JPEG, JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ. +// BMP, EMF, EMZ, GIF, JPEG, JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ. func (f *File) SetSheetBackgroundFromBytes(sheet, extension string, picture []byte) error { if len(picture) == 0 { return ErrParameterInvalid diff --git a/sheet_test.go b/sheet_test.go index f809fe8..6d2e0f6 100644 --- a/sheet_test.go +++ b/sheet_test.go @@ -596,7 +596,10 @@ func TestAttrValToFloat(t *testing.T) { func TestSetSheetBackgroundFromBytes(t *testing.T) { f := NewFile() assert.NoError(t, f.SetSheetName("Sheet1", ".svg")) - for i, imageTypes := range []string{".svg", ".emf", ".emz", ".gif", ".jpg", ".png", ".tif", ".wmf", ".wmz"} { + for i, imageTypes := range []string{ + ".svg", ".bmp", ".emf", ".emz", ".gif", + ".jpg", ".png", ".tif", ".wmf", ".wmz", + } { file := fmt.Sprintf("excelize%s", imageTypes) if i > 0 { file = filepath.Join("test", "images", fmt.Sprintf("excel%s", imageTypes)) diff --git a/styles.go b/styles.go index e2be993..5a77bc7 100644 --- a/styles.go +++ b/styles.go @@ -277,7 +277,7 @@ var langNumFmt = map[string]map[int]string{ // currencyNumFmt defined the currency number format map. var currencyNumFmt = map[int]string{ - 164: `"CN¥",##0.00`, + 164: `"¥"#,##0.00`, 165: "[$$-409]#,##0.00", 166: "[$$-45C]#,##0.00", 167: "[$$-1004]#,##0.00", @@ -1491,8 +1491,8 @@ func parseFormatStyleSet(style *Style) (*Style, error) { // // Index | Symbol // -------+--------------------------------------------------------------- -// 164 | CN¥ -// 165 | $ English (China) +// 164 | ¥ +// 165 | $ English (United States) // 166 | $ Cherokee (United States) // 167 | $ Chinese (Singapore) // 168 | $ Chinese (Taiwan) @@ -1533,28 +1533,28 @@ func parseFormatStyleSet(style *Style) (*Style, error) { // 203 | ₡ Spanish (Costa Rica) // 204 | ₦ Hausa (Nigeria) // 205 | ₦ Igbo (Nigeria) -// 206 | ₦ Yoruba (Nigeria) -// 207 | ₩ Korean (South Korea) -// 208 | ₪ Hebrew (Israel) -// 209 | ₫ Vietnamese (Vietnam) -// 210 | € Basque (Spain) -// 211 | € Breton (France) -// 212 | € Catalan (Spain) -// 213 | € Corsican (France) -// 214 | € Dutch (Belgium) -// 215 | € Dutch (Netherlands) -// 216 | € English (Ireland) -// 217 | € Estonian (Estonia) -// 218 | € Euro (€ 123) -// 219 | € Euro (123 €) -// 220 | € Finnish (Finland) -// 221 | € French (Belgium) -// 222 | € French (France) -// 223 | € French (Luxembourg) -// 224 | € French (Monaco) -// 225 | € French (Réunion) -// 226 | € Galician (Spain) -// 227 | € German (Austria) +// 206 | ₩ Korean (South Korea) +// 207 | ₪ Hebrew (Israel) +// 208 | ₫ Vietnamese (Vietnam) +// 209 | € Basque (Spain) +// 210 | € Breton (France) +// 211 | € Catalan (Spain) +// 212 | € Corsican (France) +// 213 | € Dutch (Belgium) +// 214 | € Dutch (Netherlands) +// 215 | € English (Ireland) +// 216 | € Estonian (Estonia) +// 217 | € Euro (€ 123) +// 218 | € Euro (123 €) +// 219 | € Finnish (Finland) +// 220 | € French (Belgium) +// 221 | € French (France) +// 222 | € French (Luxembourg) +// 223 | € French (Monaco) +// 224 | € French (Réunion) +// 225 | € Galician (Spain) +// 226 | € German (Austria) +// 227 | € German (German) // 228 | € German (Luxembourg) // 229 | € Greek (Greece) // 230 | € Inari Sami (Finland) diff --git a/test/images/excel.bmp b/test/images/excel.bmp new file mode 100755 index 0000000000000000000000000000000000000000..cbd3691abc49097acdc9616678ef2b58c12d83e0 GIT binary patch literal 26678 zcmeI4zi#6;9LHIpfDLphI%(wCC%BpDUf@oX94}PRq3KibJ-iS(qd@Fi@@LA#vFI~& z;3M2{mWK}Nm;6zYY)Q7Skz?r~Iv-P_Wr^S4ACgjX_sg&EerLYC`<}6%vGo^F;5#21_oHh zBm*1>fE}rT1_s!0U5;7+2^7%40LvIQndU$M2^7%40EA>mNEP=%YgtA zD4>A>mI;P#G7j8J0tGZMz>+l1Q41h}0vZ@#Nw(mq1&}}i4Ggek63I~uAb|oJ7+}d< zilY`l0tGZMz>+C7M=gK^3TR+}B{Lh2S^xA>mcra{ z)B;GLfM%cn&Dj#iDV&e7-2bpVcUu52*W~ucGFo7?z-WQ5x4<;^WwFijJd3wDK^)_4 z8)w*Ee*O6_^^Iw~*rF_4pS_Mr98U(R!}%c3m*~CMv79dU9A;y+LhfkdeMu7eoj8}`rB97-%%5#_R2rTjkjb$$HdtVA2 zE=!Of2rE}lLR@7ilX(n{eJ@i#XTSvz0v#@_Twqo6!+$mq9r=9Wb%6P>Edl=1d%ZLcs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