2021-03-30 23:02:22 +08:00
|
|
|
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
|
2018-09-14 00:44:23 +08:00
|
|
|
// this source code is governed by a BSD-style license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
//
|
|
|
|
// Package excelize providing a set of functions that allow you to write to
|
2020-06-22 00:14:56 +08:00
|
|
|
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
|
2021-03-30 23:02:22 +08:00
|
|
|
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
|
2020-06-22 00:14:56 +08:00
|
|
|
// complex components by high compatibility, and provided streaming API for
|
|
|
|
// generating or reading data from a worksheet with huge amounts of data. This
|
2021-04-04 15:29:43 +08:00
|
|
|
// library needs Go version 1.15 or later.
|
2018-09-14 00:58:48 +08:00
|
|
|
|
2017-04-30 20:03:43 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// parseFormatShapeSet provides a function to parse the format settings of the
|
2017-04-30 20:03:43 +08:00
|
|
|
// shape with default value.
|
2018-05-27 11:25:55 +08:00
|
|
|
func parseFormatShapeSet(formatSet string) (*formatShape, error) {
|
2017-04-30 20:03:43 +08:00
|
|
|
format := formatShape{
|
|
|
|
Width: 160,
|
|
|
|
Height: 160,
|
|
|
|
Format: formatPicture{
|
|
|
|
FPrintsWithSheet: true,
|
|
|
|
FLocksWithSheet: false,
|
|
|
|
NoChangeAspect: false,
|
|
|
|
OffsetX: 0,
|
|
|
|
OffsetY: 0,
|
|
|
|
XScale: 1.0,
|
|
|
|
YScale: 1.0,
|
|
|
|
},
|
|
|
|
}
|
2018-05-27 11:25:55 +08:00
|
|
|
err := json.Unmarshal([]byte(formatSet), &format)
|
|
|
|
return &format, err
|
2017-04-30 20:03:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddShape provides the method to add shape in a sheet by given worksheet
|
|
|
|
// index, shape format set (such as offset, scale, aspect ratio setting and
|
2018-08-06 10:21:24 +08:00
|
|
|
// print settings) and properties set. For example, add text box (rect shape)
|
|
|
|
// in Sheet1:
|
2017-04-30 20:03:43 +08:00
|
|
|
//
|
2019-08-21 23:03:34 +08:00
|
|
|
// err := f.AddShape("Sheet1", "G6", `{"type":"rect","color":{"line":"#4286F4","fill":"#8eb9ff"},"paragraph":[{"text":"Rectangle Shape","font":{"bold":true,"italic":true,"family":"Times New Roman","size":36,"color":"#777777","underline":"sng"}}],"width":180,"height": 90}`)
|
2017-04-30 20:03:43 +08:00
|
|
|
//
|
2018-04-23 00:14:58 +08:00
|
|
|
// The following shows the type of shape supported by excelize:
|
2017-04-30 20:03:43 +08:00
|
|
|
//
|
|
|
|
// accentBorderCallout1 (Callout 1 with Border and Accent Shape)
|
|
|
|
// accentBorderCallout2 (Callout 2 with Border and Accent Shape)
|
|
|
|
// accentBorderCallout3 (Callout 3 with Border and Accent Shape)
|
|
|
|
// accentCallout1 (Callout 1 Shape)
|
|
|
|
// accentCallout2 (Callout 2 Shape)
|
|
|
|
// accentCallout3 (Callout 3 Shape)
|
|
|
|
// actionButtonBackPrevious (Back or Previous Button Shape)
|
|
|
|
// actionButtonBeginning (Beginning Button Shape)
|
|
|
|
// actionButtonBlank (Blank Button Shape)
|
|
|
|
// actionButtonDocument (Document Button Shape)
|
|
|
|
// actionButtonEnd (End Button Shape)
|
|
|
|
// actionButtonForwardNext (Forward or Next Button Shape)
|
|
|
|
// actionButtonHelp (Help Button Shape)
|
|
|
|
// actionButtonHome (Home Button Shape)
|
|
|
|
// actionButtonInformation (Information Button Shape)
|
|
|
|
// actionButtonMovie (Movie Button Shape)
|
|
|
|
// actionButtonReturn (Return Button Shape)
|
|
|
|
// actionButtonSound (Sound Button Shape)
|
|
|
|
// arc (Curved Arc Shape)
|
|
|
|
// bentArrow (Bent Arrow Shape)
|
|
|
|
// bentConnector2 (Bent Connector 2 Shape)
|
|
|
|
// bentConnector3 (Bent Connector 3 Shape)
|
|
|
|
// bentConnector4 (Bent Connector 4 Shape)
|
|
|
|
// bentConnector5 (Bent Connector 5 Shape)
|
|
|
|
// bentUpArrow (Bent Up Arrow Shape)
|
|
|
|
// bevel (Bevel Shape)
|
|
|
|
// blockArc (Block Arc Shape)
|
|
|
|
// borderCallout1 (Callout 1 with Border Shape)
|
|
|
|
// borderCallout2 (Callout 2 with Border Shape)
|
|
|
|
// borderCallout3 (Callout 3 with Border Shape)
|
|
|
|
// bracePair (Brace Pair Shape)
|
|
|
|
// bracketPair (Bracket Pair Shape)
|
|
|
|
// callout1 (Callout 1 Shape)
|
|
|
|
// callout2 (Callout 2 Shape)
|
|
|
|
// callout3 (Callout 3 Shape)
|
|
|
|
// can (Can Shape)
|
|
|
|
// chartPlus (Chart Plus Shape)
|
|
|
|
// chartStar (Chart Star Shape)
|
|
|
|
// chartX (Chart X Shape)
|
|
|
|
// chevron (Chevron Shape)
|
|
|
|
// chord (Chord Shape)
|
|
|
|
// circularArrow (Circular Arrow Shape)
|
|
|
|
// cloud (Cloud Shape)
|
|
|
|
// cloudCallout (Callout Cloud Shape)
|
|
|
|
// corner (Corner Shape)
|
|
|
|
// cornerTabs (Corner Tabs Shape)
|
|
|
|
// cube (Cube Shape)
|
|
|
|
// curvedConnector2 (Curved Connector 2 Shape)
|
|
|
|
// curvedConnector3 (Curved Connector 3 Shape)
|
|
|
|
// curvedConnector4 (Curved Connector 4 Shape)
|
|
|
|
// curvedConnector5 (Curved Connector 5 Shape)
|
|
|
|
// curvedDownArrow (Curved Down Arrow Shape)
|
|
|
|
// curvedLeftArrow (Curved Left Arrow Shape)
|
|
|
|
// curvedRightArrow (Curved Right Arrow Shape)
|
|
|
|
// curvedUpArrow (Curved Up Arrow Shape)
|
|
|
|
// decagon (Decagon Shape)
|
|
|
|
// diagStripe (Diagonal Stripe Shape)
|
|
|
|
// diamond (Diamond Shape)
|
|
|
|
// dodecagon (Dodecagon Shape)
|
|
|
|
// donut (Donut Shape)
|
|
|
|
// doubleWave (Double Wave Shape)
|
|
|
|
// downArrow (Down Arrow Shape)
|
|
|
|
// downArrowCallout (Callout Down Arrow Shape)
|
|
|
|
// ellipse (Ellipse Shape)
|
|
|
|
// ellipseRibbon (Ellipse Ribbon Shape)
|
|
|
|
// ellipseRibbon2 (Ellipse Ribbon 2 Shape)
|
|
|
|
// flowChartAlternateProcess (Alternate Process Flow Shape)
|
|
|
|
// flowChartCollate (Collate Flow Shape)
|
|
|
|
// flowChartConnector (Connector Flow Shape)
|
|
|
|
// flowChartDecision (Decision Flow Shape)
|
|
|
|
// flowChartDelay (Delay Flow Shape)
|
|
|
|
// flowChartDisplay (Display Flow Shape)
|
|
|
|
// flowChartDocument (Document Flow Shape)
|
|
|
|
// flowChartExtract (Extract Flow Shape)
|
|
|
|
// flowChartInputOutput (Input Output Flow Shape)
|
|
|
|
// flowChartInternalStorage (Internal Storage Flow Shape)
|
|
|
|
// flowChartMagneticDisk (Magnetic Disk Flow Shape)
|
|
|
|
// flowChartMagneticDrum (Magnetic Drum Flow Shape)
|
|
|
|
// flowChartMagneticTape (Magnetic Tape Flow Shape)
|
|
|
|
// flowChartManualInput (Manual Input Flow Shape)
|
|
|
|
// flowChartManualOperation (Manual Operation Flow Shape)
|
|
|
|
// flowChartMerge (Merge Flow Shape)
|
|
|
|
// flowChartMultidocument (Multi-Document Flow Shape)
|
|
|
|
// flowChartOfflineStorage (Offline Storage Flow Shape)
|
|
|
|
// flowChartOffpageConnector (Off-Page Connector Flow Shape)
|
|
|
|
// flowChartOnlineStorage (Online Storage Flow Shape)
|
|
|
|
// flowChartOr (Or Flow Shape)
|
|
|
|
// flowChartPredefinedProcess (Predefined Process Flow Shape)
|
|
|
|
// flowChartPreparation (Preparation Flow Shape)
|
|
|
|
// flowChartProcess (Process Flow Shape)
|
|
|
|
// flowChartPunchedCard (Punched Card Flow Shape)
|
|
|
|
// flowChartPunchedTape (Punched Tape Flow Shape)
|
|
|
|
// flowChartSort (Sort Flow Shape)
|
|
|
|
// flowChartSummingJunction (Summing Junction Flow Shape)
|
|
|
|
// flowChartTerminator (Terminator Flow Shape)
|
|
|
|
// foldedCorner (Folded Corner Shape)
|
|
|
|
// frame (Frame Shape)
|
|
|
|
// funnel (Funnel Shape)
|
|
|
|
// gear6 (Gear 6 Shape)
|
|
|
|
// gear9 (Gear 9 Shape)
|
|
|
|
// halfFrame (Half Frame Shape)
|
|
|
|
// heart (Heart Shape)
|
|
|
|
// heptagon (Heptagon Shape)
|
|
|
|
// hexagon (Hexagon Shape)
|
|
|
|
// homePlate (Home Plate Shape)
|
|
|
|
// horizontalScroll (Horizontal Scroll Shape)
|
|
|
|
// irregularSeal1 (Irregular Seal 1 Shape)
|
|
|
|
// irregularSeal2 (Irregular Seal 2 Shape)
|
|
|
|
// leftArrow (Left Arrow Shape)
|
|
|
|
// leftArrowCallout (Callout Left Arrow Shape)
|
|
|
|
// leftBrace (Left Brace Shape)
|
|
|
|
// leftBracket (Left Bracket Shape)
|
|
|
|
// leftCircularArrow (Left Circular Arrow Shape)
|
|
|
|
// leftRightArrow (Left Right Arrow Shape)
|
|
|
|
// leftRightArrowCallout (Callout Left Right Arrow Shape)
|
|
|
|
// leftRightCircularArrow (Left Right Circular Arrow Shape)
|
|
|
|
// leftRightRibbon (Left Right Ribbon Shape)
|
|
|
|
// leftRightUpArrow (Left Right Up Arrow Shape)
|
|
|
|
// leftUpArrow (Left Up Arrow Shape)
|
|
|
|
// lightningBolt (Lightning Bolt Shape)
|
|
|
|
// line (Line Shape)
|
|
|
|
// lineInv (Line Inverse Shape)
|
|
|
|
// mathDivide (Divide Math Shape)
|
|
|
|
// mathEqual (Equal Math Shape)
|
|
|
|
// mathMinus (Minus Math Shape)
|
|
|
|
// mathMultiply (Multiply Math Shape)
|
|
|
|
// mathNotEqual (Not Equal Math Shape)
|
|
|
|
// mathPlus (Plus Math Shape)
|
|
|
|
// moon (Moon Shape)
|
|
|
|
// nonIsoscelesTrapezoid (Non-Isosceles Trapezoid Shape)
|
|
|
|
// noSmoking (No Smoking Shape)
|
|
|
|
// notchedRightArrow (Notched Right Arrow Shape)
|
|
|
|
// octagon (Octagon Shape)
|
|
|
|
// parallelogram (Parallelogram Shape)
|
|
|
|
// pentagon (Pentagon Shape)
|
|
|
|
// pie (Pie Shape)
|
|
|
|
// pieWedge (Pie Wedge Shape)
|
|
|
|
// plaque (Plaque Shape)
|
|
|
|
// plaqueTabs (Plaque Tabs Shape)
|
|
|
|
// plus (Plus Shape)
|
|
|
|
// quadArrow (Quad-Arrow Shape)
|
|
|
|
// quadArrowCallout (Callout Quad-Arrow Shape)
|
|
|
|
// rect (Rectangle Shape)
|
|
|
|
// ribbon (Ribbon Shape)
|
|
|
|
// ribbon2 (Ribbon 2 Shape)
|
|
|
|
// rightArrow (Right Arrow Shape)
|
|
|
|
// rightArrowCallout (Callout Right Arrow Shape)
|
|
|
|
// rightBrace (Right Brace Shape)
|
|
|
|
// rightBracket (Right Bracket Shape)
|
|
|
|
// round1Rect (One Round Corner Rectangle Shape)
|
|
|
|
// round2DiagRect (Two Diagonal Round Corner Rectangle Shape)
|
|
|
|
// round2SameRect (Two Same-side Round Corner Rectangle Shape)
|
|
|
|
// roundRect (Round Corner Rectangle Shape)
|
|
|
|
// rtTriangle (Right Triangle Shape)
|
|
|
|
// smileyFace (Smiley Face Shape)
|
|
|
|
// snip1Rect (One Snip Corner Rectangle Shape)
|
|
|
|
// snip2DiagRect (Two Diagonal Snip Corner Rectangle Shape)
|
|
|
|
// snip2SameRect (Two Same-side Snip Corner Rectangle Shape)
|
|
|
|
// snipRoundRect (One Snip One Round Corner Rectangle Shape)
|
|
|
|
// squareTabs (Square Tabs Shape)
|
|
|
|
// star10 (Ten Pointed Star Shape)
|
|
|
|
// star12 (Twelve Pointed Star Shape)
|
|
|
|
// star16 (Sixteen Pointed Star Shape)
|
|
|
|
// star24 (Twenty Four Pointed Star Shape)
|
|
|
|
// star32 (Thirty Two Pointed Star Shape)
|
|
|
|
// star4 (Four Pointed Star Shape)
|
|
|
|
// star5 (Five Pointed Star Shape)
|
|
|
|
// star6 (Six Pointed Star Shape)
|
|
|
|
// star7 (Seven Pointed Star Shape)
|
|
|
|
// star8 (Eight Pointed Star Shape)
|
|
|
|
// straightConnector1 (Straight Connector 1 Shape)
|
|
|
|
// stripedRightArrow (Striped Right Arrow Shape)
|
|
|
|
// sun (Sun Shape)
|
|
|
|
// swooshArrow (Swoosh Arrow Shape)
|
|
|
|
// teardrop (Teardrop Shape)
|
|
|
|
// trapezoid (Trapezoid Shape)
|
|
|
|
// triangle (Triangle Shape)
|
|
|
|
// upArrow (Up Arrow Shape)
|
|
|
|
// upArrowCallout (Callout Up Arrow Shape)
|
|
|
|
// upDownArrow (Up Down Arrow Shape)
|
|
|
|
// upDownArrowCallout (Callout Up Down Arrow Shape)
|
|
|
|
// uturnArrow (U-Turn Arrow Shape)
|
|
|
|
// verticalScroll (Vertical Scroll Shape)
|
|
|
|
// wave (Wave Shape)
|
|
|
|
// wedgeEllipseCallout (Callout Wedge Ellipse Shape)
|
|
|
|
// wedgeRectCallout (Callout Wedge Rectangle Shape)
|
|
|
|
// wedgeRoundRectCallout (Callout Wedge Round Rectangle Shape)
|
|
|
|
//
|
2017-05-16 20:42:01 +08:00
|
|
|
// The following shows the type of text underline supported by excelize:
|
|
|
|
//
|
|
|
|
// none
|
|
|
|
// words
|
|
|
|
// sng
|
|
|
|
// dbl
|
|
|
|
// heavy
|
|
|
|
// dotted
|
|
|
|
// dottedHeavy
|
|
|
|
// dash
|
|
|
|
// dashHeavy
|
|
|
|
// dashLong
|
|
|
|
// dashLongHeavy
|
|
|
|
// dotDash
|
|
|
|
// dotDashHeavy
|
|
|
|
// dotDotDash
|
|
|
|
// dotDotDashHeavy
|
|
|
|
// wavy
|
|
|
|
// wavyHeavy
|
|
|
|
// wavyDbl
|
|
|
|
//
|
2018-05-27 11:25:55 +08:00
|
|
|
func (f *File) AddShape(sheet, cell, format string) error {
|
|
|
|
formatSet, err := parseFormatShapeSet(format)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-04-30 20:03:43 +08:00
|
|
|
// Read sheet data.
|
2020-11-10 23:48:09 +08:00
|
|
|
ws, err := f.workSheetReader(sheet)
|
2019-04-15 11:22:57 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-04-30 20:03:43 +08:00
|
|
|
// Add first shape for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
|
|
|
|
drawingID := f.countDrawings() + 1
|
|
|
|
drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
|
|
|
|
sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
|
|
|
|
|
2020-11-10 23:48:09 +08:00
|
|
|
if ws.Drawing != nil {
|
2017-04-30 20:03:43 +08:00
|
|
|
// The worksheet already has a shape or chart relationships, use the relationships drawing ../drawings/drawing%d.xml.
|
2020-11-10 23:48:09 +08:00
|
|
|
sheetRelationshipsDrawingXML = f.getSheetRelationshipsTargetByID(sheet, ws.Drawing.RID)
|
2017-04-30 20:03:43 +08:00
|
|
|
drawingID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingXML, "../drawings/drawing"), ".xml"))
|
|
|
|
drawingXML = strings.Replace(sheetRelationshipsDrawingXML, "..", "xl", -1)
|
|
|
|
} else {
|
|
|
|
// Add first shape for given sheet.
|
2019-12-23 00:07:40 +08:00
|
|
|
sheetRels := "xl/worksheets/_rels/" + strings.TrimPrefix(f.sheetMap[trimSheetName(sheet)], "xl/worksheets/") + ".rels"
|
2019-09-16 01:17:35 +08:00
|
|
|
rID := f.addRels(sheetRels, SourceRelationshipDrawingML, sheetRelationshipsDrawingXML, "")
|
2017-04-30 20:03:43 +08:00
|
|
|
f.addSheetDrawing(sheet, rID)
|
2020-07-18 15:15:16 +08:00
|
|
|
f.addSheetNameSpace(sheet, SourceRelationship)
|
2017-04-30 20:03:43 +08:00
|
|
|
}
|
2019-03-23 20:08:06 +08:00
|
|
|
err = f.addDrawingShape(sheet, drawingXML, cell, formatSet)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-24 14:17:35 +08:00
|
|
|
f.addContentTypePart(drawingID, "drawings")
|
2018-05-27 11:25:55 +08:00
|
|
|
return err
|
2017-04-30 20:03:43 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// addDrawingShape provides a function to add preset geometry by given sheet,
|
2017-05-24 14:17:35 +08:00
|
|
|
// drawingXMLand format sets.
|
2019-03-23 20:08:06 +08:00
|
|
|
func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *formatShape) error {
|
|
|
|
fromCol, fromRow, err := CellNameToCoordinates(cell)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
colIdx := fromCol - 1
|
|
|
|
rowIdx := fromRow - 1
|
|
|
|
|
|
|
|
textUnderlineType := map[string]bool{
|
|
|
|
"none": true,
|
|
|
|
"words": true,
|
|
|
|
"sng": true,
|
|
|
|
"dbl": true,
|
|
|
|
"heavy": true,
|
|
|
|
"dotted": true,
|
|
|
|
"dottedHeavy": true,
|
|
|
|
"dash": true,
|
|
|
|
"dashHeavy": true,
|
|
|
|
"dashLong": true,
|
|
|
|
"dashLongHeavy": true,
|
|
|
|
"dotDash": true,
|
|
|
|
"dotDashHeavy": true,
|
|
|
|
"dotDotDash": true,
|
|
|
|
"dotDotDashHeavy": true,
|
|
|
|
"wavy": true,
|
|
|
|
"wavyHeavy": true,
|
|
|
|
"wavyDbl": true,
|
|
|
|
}
|
|
|
|
|
2017-04-30 20:03:43 +08:00
|
|
|
width := int(float64(formatSet.Width) * formatSet.Format.XScale)
|
|
|
|
height := int(float64(formatSet.Height) * formatSet.Format.YScale)
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
|
2020-10-18 00:01:33 +08:00
|
|
|
colStart, rowStart, colEnd, rowEnd, x2, y2 :=
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
f.positionObjectPixels(sheet, colIdx, rowIdx, formatSet.Format.OffsetX, formatSet.Format.OffsetY,
|
|
|
|
width, height)
|
2019-02-25 22:14:34 +08:00
|
|
|
content, cNvPrID := f.drawingParser(drawingXML)
|
2017-04-30 20:03:43 +08:00
|
|
|
twoCellAnchor := xdrCellAnchor{}
|
2018-04-26 11:41:13 +08:00
|
|
|
twoCellAnchor.EditAs = formatSet.Format.Positioning
|
2017-04-30 20:03:43 +08:00
|
|
|
from := xlsxFrom{}
|
|
|
|
from.Col = colStart
|
|
|
|
from.ColOff = formatSet.Format.OffsetX * EMU
|
|
|
|
from.Row = rowStart
|
|
|
|
from.RowOff = formatSet.Format.OffsetY * EMU
|
|
|
|
to := xlsxTo{}
|
|
|
|
to.Col = colEnd
|
|
|
|
to.ColOff = x2 * EMU
|
|
|
|
to.Row = rowEnd
|
|
|
|
to.RowOff = y2 * EMU
|
|
|
|
twoCellAnchor.From = &from
|
|
|
|
twoCellAnchor.To = &to
|
|
|
|
shape := xdrSp{
|
|
|
|
NvSpPr: &xdrNvSpPr{
|
|
|
|
CNvPr: &xlsxCNvPr{
|
|
|
|
ID: cNvPrID,
|
|
|
|
Name: "Shape " + strconv.Itoa(cNvPrID),
|
|
|
|
},
|
|
|
|
CNvSpPr: &xdrCNvSpPr{
|
|
|
|
TxBox: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SpPr: &xlsxSpPr{
|
|
|
|
PrstGeom: xlsxPrstGeom{
|
|
|
|
Prst: formatSet.Type,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Style: &xdrStyle{
|
|
|
|
LnRef: setShapeRef(formatSet.Color.Line, 2),
|
|
|
|
FillRef: setShapeRef(formatSet.Color.Fill, 1),
|
|
|
|
EffectRef: setShapeRef(formatSet.Color.Effect, 0),
|
|
|
|
FontRef: &aFontRef{
|
|
|
|
Idx: "minor",
|
|
|
|
SchemeClr: &attrValString{
|
2019-12-23 00:07:40 +08:00
|
|
|
Val: stringPtr("tx1"),
|
2017-04-30 20:03:43 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TxBody: &xdrTxBody{
|
|
|
|
BodyPr: &aBodyPr{
|
|
|
|
VertOverflow: "clip",
|
|
|
|
HorzOverflow: "clip",
|
|
|
|
Wrap: "none",
|
|
|
|
RtlCol: false,
|
|
|
|
Anchor: "t",
|
|
|
|
},
|
2017-06-19 11:18:58 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
if len(formatSet.Paragraph) < 1 {
|
|
|
|
formatSet.Paragraph = []formatShapeParagraph{
|
|
|
|
{
|
2020-03-10 00:04:23 +08:00
|
|
|
Font: Font{
|
2017-06-19 11:18:58 +08:00
|
|
|
Bold: false,
|
|
|
|
Italic: false,
|
|
|
|
Underline: "none",
|
2019-04-26 00:24:25 +08:00
|
|
|
Family: f.GetDefaultFont(),
|
2017-06-19 11:18:58 +08:00
|
|
|
Size: 11,
|
|
|
|
Color: "#000000",
|
|
|
|
},
|
|
|
|
Text: " ",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, p := range formatSet.Paragraph {
|
|
|
|
u := p.Font.Underline
|
|
|
|
_, ok := textUnderlineType[u]
|
|
|
|
if !ok {
|
|
|
|
u = "none"
|
|
|
|
}
|
|
|
|
text := p.Text
|
|
|
|
if text == "" {
|
|
|
|
text = " "
|
|
|
|
}
|
|
|
|
paragraph := &aP{
|
|
|
|
R: &aR{
|
|
|
|
RPr: aRPr{
|
|
|
|
I: p.Font.Italic,
|
|
|
|
B: p.Font.Bold,
|
|
|
|
Lang: "en-US",
|
|
|
|
AltLang: "en-US",
|
|
|
|
U: u,
|
|
|
|
Sz: p.Font.Size * 100,
|
|
|
|
Latin: &aLatin{Typeface: p.Font.Family},
|
2017-04-30 20:03:43 +08:00
|
|
|
},
|
2017-06-19 11:18:58 +08:00
|
|
|
T: text,
|
2017-04-30 20:03:43 +08:00
|
|
|
},
|
2017-06-19 11:18:58 +08:00
|
|
|
EndParaRPr: &aEndParaRPr{
|
|
|
|
Lang: "en-US",
|
|
|
|
},
|
|
|
|
}
|
2019-09-26 22:28:14 +08:00
|
|
|
srgbClr := strings.Replace(strings.ToUpper(p.Font.Color), "#", "", -1)
|
|
|
|
if len(srgbClr) == 6 {
|
|
|
|
paragraph.R.RPr.SolidFill = &aSolidFill{
|
|
|
|
SrgbClr: &attrValString{
|
2019-12-23 00:07:40 +08:00
|
|
|
Val: stringPtr(srgbClr),
|
2019-09-26 22:28:14 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2017-06-19 11:18:58 +08:00
|
|
|
shape.TxBody.P = append(shape.TxBody.P, paragraph)
|
2017-04-30 20:03:43 +08:00
|
|
|
}
|
|
|
|
twoCellAnchor.Sp = &shape
|
|
|
|
twoCellAnchor.ClientData = &xdrClientData{
|
|
|
|
FLocksWithSheet: formatSet.Format.FLocksWithSheet,
|
|
|
|
FPrintsWithSheet: formatSet.Format.FPrintsWithSheet,
|
|
|
|
}
|
|
|
|
content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor)
|
2019-02-25 22:14:34 +08:00
|
|
|
f.Drawings[drawingXML] = content
|
2019-03-23 20:08:06 +08:00
|
|
|
return err
|
2017-04-30 20:03:43 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// setShapeRef provides a function to set color with hex model by given actual
|
2017-04-30 20:03:43 +08:00
|
|
|
// color value.
|
|
|
|
func setShapeRef(color string, i int) *aRef {
|
|
|
|
if color == "" {
|
|
|
|
return &aRef{
|
|
|
|
Idx: 0,
|
|
|
|
ScrgbClr: &aScrgbClr{
|
|
|
|
R: 0,
|
|
|
|
G: 0,
|
|
|
|
B: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &aRef{
|
|
|
|
Idx: i,
|
|
|
|
SrgbClr: &attrValString{
|
2019-12-23 00:07:40 +08:00
|
|
|
Val: stringPtr(strings.Replace(strings.ToUpper(color), "#", "", -1)),
|
2017-04-30 20:03:43 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|