Skip to content

Commit 0f5fa2d

Browse files
committed
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
1 parent 12645e7 commit 0f5fa2d

File tree

8 files changed

+54
-37
lines changed

8 files changed

+54
-37
lines changed

picture.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func parseGraphicOptions(opts *GraphicOptions) *GraphicOptions {
5151

5252
// AddPicture provides the method to add picture in a sheet by given picture
5353
// format set (such as offset, scale, aspect ratio setting and print settings)
54-
// and file path, supported image types: EMF, EMZ, GIF, JPEG, JPG, PNG, SVG,
55-
// TIF, TIFF, WMF, and WMZ. This function is concurrency safe. For example:
54+
// and file path, supported image types: BMP, EMF, EMZ, GIF, JPEG, JPG, PNG,
55+
// SVG, TIF, TIFF, WMF, and WMZ. This function is concurrency safe. For example:
5656
//
5757
// package main
5858
//
@@ -436,8 +436,9 @@ func (f *File) addMedia(file []byte, ext string) string {
436436
// type for relationship parts and the Main Document part.
437437
func (f *File) setContentTypePartImageExtensions() error {
438438
imageTypes := map[string]string{
439-
"jpeg": "image/", "png": "image/", "gif": "image/", "svg": "image/", "tiff": "image/",
440-
"emf": "image/x-", "wmf": "image/x-", "emz": "image/x-", "wmz": "image/x-",
439+
"bmp": "image/", "jpeg": "image/", "png": "image/", "gif": "image/",
440+
"svg": "image/", "tiff": "image/", "emf": "image/x-", "wmf": "image/x-",
441+
"emz": "image/x-", "wmz": "image/x-",
441442
}
442443
content, err := f.contentTypesReader()
443444
if err != nil {

picture_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"testing"
1414

15+
_ "golang.org/x/image/bmp"
1516
_ "golang.org/x/image/tiff"
1617

1718
"github.com/stretchr/testify/assert"
@@ -64,6 +65,7 @@ func TestAddPicture(t *testing.T) {
6465
assert.NoError(t, f.AddPicture("Sheet1", "Q8", filepath.Join("test", "images", "excel.gif"), nil))
6566
assert.NoError(t, f.AddPicture("Sheet1", "Q15", filepath.Join("test", "images", "excel.jpg"), nil))
6667
assert.NoError(t, f.AddPicture("Sheet1", "Q22", filepath.Join("test", "images", "excel.tif"), nil))
68+
assert.NoError(t, f.AddPicture("Sheet1", "Q28", filepath.Join("test", "images", "excel.bmp"), nil))
6769

6870
// Test write file to given path
6971
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddPicture1.xlsx")))

sheet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ func (f *File) getSheetXMLPath(sheet string) (string, bool) {
500500
}
501501

502502
// SetSheetBackground provides a function to set background picture by given
503-
// worksheet name and file path. Supported image types: EMF, EMZ, GIF, JPEG,
504-
// JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ.
503+
// worksheet name and file path. Supported image types: BMP, EMF, EMZ, GIF,
504+
// JPEG, JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ.
505505
func (f *File) SetSheetBackground(sheet, picture string) error {
506506
var err error
507507
// Check picture exists first.
@@ -514,7 +514,7 @@ func (f *File) SetSheetBackground(sheet, picture string) error {
514514

515515
// SetSheetBackgroundFromBytes provides a function to set background picture by
516516
// given worksheet name, extension name and image data. Supported image types:
517-
// EMF, EMZ, GIF, JPEG, JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ.
517+
// BMP, EMF, EMZ, GIF, JPEG, JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ.
518518
func (f *File) SetSheetBackgroundFromBytes(sheet, extension string, picture []byte) error {
519519
if len(picture) == 0 {
520520
return ErrParameterInvalid

sheet_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,10 @@ func TestAttrValToFloat(t *testing.T) {
596596
func TestSetSheetBackgroundFromBytes(t *testing.T) {
597597
f := NewFile()
598598
assert.NoError(t, f.SetSheetName("Sheet1", ".svg"))
599-
for i, imageTypes := range []string{".svg", ".emf", ".emz", ".gif", ".jpg", ".png", ".tif", ".wmf", ".wmz"} {
599+
for i, imageTypes := range []string{
600+
".svg", ".bmp", ".emf", ".emz", ".gif",
601+
".jpg", ".png", ".tif", ".wmf", ".wmz",
602+
} {
600603
file := fmt.Sprintf("excelize%s", imageTypes)
601604
if i > 0 {
602605
file = filepath.Join("test", "images", fmt.Sprintf("excel%s", imageTypes))

styles.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ var langNumFmt = map[string]map[int]string{
277277

278278
// currencyNumFmt defined the currency number format map.
279279
var currencyNumFmt = map[int]string{
280-
164: `"CN¥",##0.00`,
280+
164: `"¥"#,##0.00`,
281281
165: "[$$-409]#,##0.00",
282282
166: "[$$-45C]#,##0.00",
283283
167: "[$$-1004]#,##0.00",
@@ -1491,8 +1491,8 @@ func parseFormatStyleSet(style *Style) (*Style, error) {
14911491
//
14921492
// Index | Symbol
14931493
// -------+---------------------------------------------------------------
1494-
// 164 | CN¥
1495-
// 165 | $ English (China)
1494+
// 164 | ¥
1495+
// 165 | $ English (United States)
14961496
// 166 | $ Cherokee (United States)
14971497
// 167 | $ Chinese (Singapore)
14981498
// 168 | $ Chinese (Taiwan)
@@ -1533,28 +1533,28 @@ func parseFormatStyleSet(style *Style) (*Style, error) {
15331533
// 203 | ₡ Spanish (Costa Rica)
15341534
// 204 | ₦ Hausa (Nigeria)
15351535
// 205 | ₦ Igbo (Nigeria)
1536-
// 206 | ₦ Yoruba (Nigeria)
1537-
// 207 | ₩ Korean (South Korea)
1538-
// 208 | ₪ Hebrew (Israel)
1539-
// 209 | ₫ Vietnamese (Vietnam)
1540-
// 210 | € Basque (Spain)
1541-
// 211 | € Breton (France)
1542-
// 212 | € Catalan (Spain)
1543-
// 213 | € Corsican (France)
1544-
// 214 | € Dutch (Belgium)
1545-
// 215 | € Dutch (Netherlands)
1546-
// 216 | € English (Ireland)
1547-
// 217 | € Estonian (Estonia)
1548-
// 218 | € Euro (123)
1549-
// 219 | € Euro (123 €)
1550-
// 220 | € Finnish (Finland)
1551-
// 221 | € French (Belgium)
1552-
// 222 | € French (France)
1553-
// 223 | € French (Luxembourg)
1554-
// 224 | € French (Monaco)
1555-
// 225 | € French (Réunion)
1556-
// 226 | € Galician (Spain)
1557-
// 227 | € German (Austria)
1536+
// 206 | ₩ Korean (South Korea)
1537+
// 207 | ₪ Hebrew (Israel)
1538+
// 208 | ₫ Vietnamese (Vietnam)
1539+
// 209 | € Basque (Spain)
1540+
// 210 | € Breton (France)
1541+
// 211 | € Catalan (Spain)
1542+
// 212 | € Corsican (France)
1543+
// 213 | € Dutch (Belgium)
1544+
// 214 | € Dutch (Netherlands)
1545+
// 215 | € English (Ireland)
1546+
// 216 | € Estonian (Estonia)
1547+
// 217 | € Euro (€ 123)
1548+
// 218 | € Euro (123)
1549+
// 219 | € Finnish (Finland)
1550+
// 220 | € French (Belgium)
1551+
// 221 | € French (France)
1552+
// 222 | € French (Luxembourg)
1553+
// 223 | € French (Monaco)
1554+
// 224 | € French (Réunion)
1555+
// 225 | € Galician (Spain)
1556+
// 226 | € German (Austria)
1557+
// 227 | € German (German)
15581558
// 228 | € German (Luxembourg)
15591559
// 229 | € Greek (Greece)
15601560
// 230 | € Inari Sami (Finland)

test/images/excel.bmp

50.1 KB
Binary file not shown.

xmlDrawing.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ var IndexedColorMapping = []string{
181181

182182
// supportedImageTypes defined supported image types.
183183
var supportedImageTypes = map[string]string{
184-
".emf": ".emf", ".emz": ".emz", ".gif": ".gif", ".jpeg": ".jpeg",
185-
".jpg": ".jpeg", ".png": ".png", ".svg": ".svg", ".tif": ".tiff",
186-
".tiff": ".tiff", ".wmf": ".wmf", ".wmz": ".wmz",
184+
".bmp": ".bmp", ".emf": ".emf", ".emz": ".emz", ".gif": ".gif",
185+
".jpeg": ".jpeg", ".jpg": ".jpeg", ".png": ".png", ".svg": ".svg",
186+
".tif": ".tiff", ".tiff": ".tiff", ".wmf": ".wmf", ".wmz": ".wmz",
187187
}
188188

189189
// supportedContentTypes defined supported file format types.

xmlWorkbook.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type xlsxWorkbook struct {
4545
WorkbookProtection *xlsxWorkbookProtection `xml:"workbookProtection"`
4646
BookViews *xlsxBookViews `xml:"bookViews"`
4747
Sheets xlsxSheets `xml:"sheets"`
48-
FunctionGroups *xlsxExtLst `xml:"functionGroups"`
48+
FunctionGroups *xlsxFunctionGroups `xml:"functionGroups"`
4949
ExternalReferences *xlsxExternalReferences `xml:"externalReferences"`
5050
DefinedNames *xlsxDefinedNames `xml:"definedNames"`
5151
CalcPr *xlsxCalcPr `xml:"calcPr"`
@@ -171,6 +171,17 @@ type xlsxSheet struct {
171171
State string `xml:"state,attr,omitempty"`
172172
}
173173

174+
// xlsxFunctionGroup represents a single function group.
175+
type xlsxFunctionGroup struct {
176+
Name string `xml:"name,attr"`
177+
}
178+
179+
// xlsxFunctionGroups defines the collection of function groups for the workbook.
180+
type xlsxFunctionGroups struct {
181+
BuiltInGroupCount *int `xml:"builtInGroupCount,attr"`
182+
FunctionGroup []xlsxFunctionGroup `xml:"functionGroup"`
183+
}
184+
174185
// xlsxExternalReferences directly maps the externalReferences element of the
175186
// external workbook references part.
176187
type xlsxExternalReferences struct {

0 commit comments

Comments
 (0)