Fixes #256 and format document.

This commit is contained in:
xuri 2018-08-06 10:21:24 +08:00
parent efe3219af0
commit ec37b114c3
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
15 changed files with 320 additions and 309 deletions

64
cell.go
View File

@ -20,7 +20,7 @@ const (
STCellFormulaTypeShared = "shared" STCellFormulaTypeShared = "shared"
) )
// mergeCellsParser provides function to check merged cells in worksheet by // mergeCellsParser provides a function to check merged cells in worksheet by
// given axis. // given axis.
func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string { func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
axis = strings.ToUpper(axis) axis = strings.ToUpper(axis)
@ -34,8 +34,8 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
return axis return axis
} }
// SetCellValue provides function to set value of a cell. The following shows // SetCellValue provides a function to set value of a cell. The following
// the supported data types: // shows the supported data types:
// //
// int // int
// int8 // int8
@ -83,7 +83,7 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) {
} }
} }
// setCellIntValue provides function to set int value of a cell. // setCellIntValue provides a function to set int value of a cell.
func (f *File) setCellIntValue(sheet, axis string, value interface{}) { func (f *File) setCellIntValue(sheet, axis string, value interface{}) {
switch value.(type) { switch value.(type) {
case int: case int:
@ -111,7 +111,7 @@ func (f *File) setCellIntValue(sheet, axis string, value interface{}) {
} }
} }
// SetCellBool provides function to set bool type value of a cell by given // SetCellBool provides a function to set bool type value of a cell by given
// worksheet name, cell coordinates and cell value. // worksheet name, cell coordinates and cell value.
func (f *File) SetCellBool(sheet, axis string, value bool) { func (f *File) SetCellBool(sheet, axis string, value bool) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -139,10 +139,10 @@ func (f *File) SetCellBool(sheet, axis string, value bool) {
} }
} }
// GetCellValue provides function to get formatted value from cell by given // GetCellValue provides a function to get formatted value from cell by given
// worksheet name and axis in XLSX file. If it is possible to apply a format to // worksheet name and axis in XLSX file. If it is possible to apply a format
// the cell value, it will do so, if not then an error will be returned, along // to the cell value, it will do so, if not then an error will be returned,
// with the raw value of the cell. // along with the raw value of the cell.
func (f *File) GetCellValue(sheet, axis string) string { func (f *File) GetCellValue(sheet, axis string) string {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = f.mergeCellsParser(xlsx, axis) axis = f.mergeCellsParser(xlsx, axis)
@ -174,9 +174,9 @@ func (f *File) GetCellValue(sheet, axis string) string {
return "" return ""
} }
// formattedValue provides function to returns a value after formatted. If it is // formattedValue provides a function to returns a value after formatted. If
// possible to apply a format to the cell value, it will do so, if not then an // it is possible to apply a format to the cell value, it will do so, if not
// error will be returned, along with the raw value of the cell. // then an error will be returned, along with the raw value of the cell.
func (f *File) formattedValue(s int, v string) string { func (f *File) formattedValue(s int, v string) string {
if s == 0 { if s == 0 {
return v return v
@ -189,7 +189,7 @@ func (f *File) formattedValue(s int, v string) string {
return v return v
} }
// GetCellStyle provides function to get cell style index by given worksheet // GetCellStyle provides a function to get cell style index by given worksheet
// name and cell coordinates. // name and cell coordinates.
func (f *File) GetCellStyle(sheet, axis string) int { func (f *File) GetCellStyle(sheet, axis string) int {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -211,8 +211,8 @@ func (f *File) GetCellStyle(sheet, axis string) int {
return f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S) return f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S)
} }
// GetCellFormula provides function to get formula from cell by given worksheet // GetCellFormula provides a function to get formula from cell by given
// name and axis in XLSX file. // worksheet name and axis in XLSX file.
func (f *File) GetCellFormula(sheet, axis string) string { func (f *File) GetCellFormula(sheet, axis string) string {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = f.mergeCellsParser(xlsx, axis) axis = f.mergeCellsParser(xlsx, axis)
@ -276,7 +276,7 @@ func getSharedForumula(xlsx *xlsxWorksheet, si string) string {
return "" return ""
} }
// SetCellFormula provides function to set cell formula by given string and // SetCellFormula provides a function to set cell formula by given string and
// worksheet name. // worksheet name.
func (f *File) SetCellFormula(sheet, axis, formula string) { func (f *File) SetCellFormula(sheet, axis, formula string) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -305,10 +305,10 @@ func (f *File) SetCellFormula(sheet, axis, formula string) {
} }
} }
// SetCellHyperLink provides function to set cell hyperlink by given worksheet // SetCellHyperLink provides a function to set cell hyperlink by given
// name and link URL address. LinkType defines two types of hyperlink "External" // worksheet name and link URL address. LinkType defines two types of
// for web site or "Location" for moving to one of cell in this workbook. The // hyperlink "External" for web site or "Location" for moving to one of cell
// below is example for external link. // in this workbook. The below is example for external link.
// //
// xlsx.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External") // xlsx.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
// // Set underline and font color style for the cell. // // Set underline and font color style for the cell.
@ -341,10 +341,10 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) {
xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, hyperlink) xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, hyperlink)
} }
// GetCellHyperLink provides function to get cell hyperlink by given worksheet // GetCellHyperLink provides a function to get cell hyperlink by given
// name and axis. Boolean type value link will be ture if the cell has a // worksheet name and axis. Boolean type value link will be ture if the cell
// hyperlink and the target is the address of the hyperlink. Otherwise, the // has a hyperlink and the target is the address of the hyperlink. Otherwise,
// value of link will be false and the value of the target will be a blank // the value of link will be false and the value of the target will be a blank
// string. For example get hyperlink of Sheet1!H6: // string. For example get hyperlink of Sheet1!H6:
// //
// link, target := xlsx.GetCellHyperLink("Sheet1", "H6") // link, target := xlsx.GetCellHyperLink("Sheet1", "H6")
@ -369,8 +369,8 @@ func (f *File) GetCellHyperLink(sheet, axis string) (bool, string) {
return link, target return link, target
} }
// MergeCell provides function to merge cells by given coordinate area and sheet // MergeCell provides a function to merge cells by given coordinate area and
// name. For example create a merged cell of D3:E9 on Sheet1: // sheet name. For example create a merged cell of D3:E9 on Sheet1:
// //
// xlsx.MergeCell("Sheet1", "D3", "E9") // xlsx.MergeCell("Sheet1", "D3", "E9")
// //
@ -429,7 +429,7 @@ func (f *File) MergeCell(sheet, hcell, vcell string) {
} }
} }
// SetCellInt provides function to set int type value of a cell by given // SetCellInt provides a function to set int type value of a cell by given
// worksheet name, cell coordinates and cell value. // worksheet name, cell coordinates and cell value.
func (f *File) SetCellInt(sheet, axis string, value int) { func (f *File) SetCellInt(sheet, axis string, value int) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -453,7 +453,7 @@ func (f *File) SetCellInt(sheet, axis string, value int) {
xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value) xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value)
} }
// prepareCellStyle provides function to prepare style index of cell in // prepareCellStyle provides a function to prepare style index of cell in
// worksheet by given column index and style index. // worksheet by given column index and style index.
func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int { func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int {
if xlsx.Cols != nil && style == 0 { if xlsx.Cols != nil && style == 0 {
@ -466,8 +466,8 @@ func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int {
return style return style
} }
// SetCellStr provides function to set string type value of a cell. Total number // SetCellStr provides a function to set string type value of a cell. Total
// of characters that a cell can contain 32767 characters. // number of characters that a cell can contain 32767 characters.
func (f *File) SetCellStr(sheet, axis, value string) { func (f *File) SetCellStr(sheet, axis, value string) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
axis = f.mergeCellsParser(xlsx, axis) axis = f.mergeCellsParser(xlsx, axis)
@ -502,7 +502,7 @@ func (f *File) SetCellStr(sheet, axis, value string) {
xlsx.SheetData.Row[xAxis].C[yAxis].V = value xlsx.SheetData.Row[xAxis].C[yAxis].V = value
} }
// SetCellDefault provides function to set string type value of a cell as // SetCellDefault provides a function to set string type value of a cell as
// default format without escaping the cell. // default format without escaping the cell.
func (f *File) SetCellDefault(sheet, axis, value string) { func (f *File) SetCellDefault(sheet, axis, value string) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -567,7 +567,7 @@ func (f *File) SetSheetRow(sheet, axis string, slice interface{}) {
} }
} }
// checkCellInArea provides function to determine if a given coordinate is // checkCellInArea provides a function to determine if a given coordinate is
// within an area. // within an area.
func checkCellInArea(cell, area string) bool { func checkCellInArea(cell, area string) bool {
cell = strings.ToUpper(cell) cell = strings.ToUpper(cell)

View File

@ -190,7 +190,7 @@ var (
} }
) )
// parseFormatChartSet provides function to parse the format settings of the // parseFormatChartSet provides a function to parse the format settings of the
// chart with default value. // chart with default value.
func parseFormatChartSet(formatSet string) (*formatChart, error) { func parseFormatChartSet(formatSet string) (*formatChart, error) {
format := formatChart{ format := formatChart{
@ -379,7 +379,7 @@ func (f *File) AddChart(sheet, cell, format string) error {
return err return err
} }
// countCharts provides function to get chart files count storage in the // countCharts provides a function to get chart files count storage in the
// folder xl/charts. // folder xl/charts.
func (f *File) countCharts() int { func (f *File) countCharts() int {
count := 0 count := 0
@ -391,7 +391,7 @@ func (f *File) countCharts() int {
return count return count
} }
// prepareDrawing provides function to prepare drawing ID and XML by given // prepareDrawing provides a function to prepare drawing ID and XML by given
// drawingID, worksheet name and default drawingXML. // drawingID, worksheet name and default drawingXML.
func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) { func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) {
sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml" sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
@ -408,8 +408,8 @@ func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawing
return drawingID, drawingXML return drawingID, drawingXML
} }
// addChart provides function to create chart as xl/charts/chart%d.xml by given // addChart provides a function to create chart as xl/charts/chart%d.xml by
// format sets. // given format sets.
func (f *File) addChart(formatSet *formatChart) { func (f *File) addChart(formatSet *formatChart) {
count := f.countCharts() count := f.countCharts()
xlsxChartSpace := xlsxChartSpace{ xlsxChartSpace := xlsxChartSpace{
@ -564,7 +564,7 @@ func (f *File) addChart(formatSet *formatChart) {
f.saveFileList(media, chart) f.saveFileList(media, chart)
} }
// drawBaseChart provides function to draw the c:plotArea element for bar, // drawBaseChart provides a function to draw the c:plotArea element for bar,
// and column series charts by given format sets. // and column series charts by given format sets.
func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea { func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea {
c := cCharts{ c := cCharts{
@ -661,7 +661,7 @@ func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea {
return charts[formatSet.Type] return charts[formatSet.Type]
} }
// drawDoughnutChart provides function to draw the c:plotArea element for // drawDoughnutChart provides a function to draw the c:plotArea element for
// doughnut chart by given format sets. // doughnut chart by given format sets.
func (f *File) drawDoughnutChart(formatSet *formatChart) *cPlotArea { func (f *File) drawDoughnutChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{ return &cPlotArea{
@ -675,8 +675,8 @@ func (f *File) drawDoughnutChart(formatSet *formatChart) *cPlotArea {
} }
} }
// drawLineChart provides function to draw the c:plotArea element for line chart // drawLineChart provides a function to draw the c:plotArea element for line
// by given format sets. // chart by given format sets.
func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea { func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{ return &cPlotArea{
LineChart: &cCharts{ LineChart: &cCharts{
@ -701,8 +701,8 @@ func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea {
} }
} }
// drawPieChart provides function to draw the c:plotArea element for pie chart // drawPieChart provides a function to draw the c:plotArea element for pie
// by given format sets. // chart by given format sets.
func (f *File) drawPieChart(formatSet *formatChart) *cPlotArea { func (f *File) drawPieChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{ return &cPlotArea{
PieChart: &cCharts{ PieChart: &cCharts{
@ -714,8 +714,8 @@ func (f *File) drawPieChart(formatSet *formatChart) *cPlotArea {
} }
} }
// drawPie3DChart provides function to draw the c:plotArea element for 3D pie // drawPie3DChart provides a function to draw the c:plotArea element for 3D
// chart by given format sets. // pie chart by given format sets.
func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea { func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{ return &cPlotArea{
Pie3DChart: &cCharts{ Pie3DChart: &cCharts{
@ -727,7 +727,7 @@ func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea {
} }
} }
// drawRadarChart provides function to draw the c:plotArea element for radar // drawRadarChart provides a function to draw the c:plotArea element for radar
// chart by given format sets. // chart by given format sets.
func (f *File) drawRadarChart(formatSet *formatChart) *cPlotArea { func (f *File) drawRadarChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{ return &cPlotArea{
@ -750,8 +750,8 @@ func (f *File) drawRadarChart(formatSet *formatChart) *cPlotArea {
} }
} }
// drawScatterChart provides function to draw the c:plotArea element for scatter // drawScatterChart provides a function to draw the c:plotArea element for
// chart by given format sets. // scatter chart by given format sets.
func (f *File) drawScatterChart(formatSet *formatChart) *cPlotArea { func (f *File) drawScatterChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{ return &cPlotArea{
ScatterChart: &cCharts{ ScatterChart: &cCharts{
@ -773,8 +773,8 @@ func (f *File) drawScatterChart(formatSet *formatChart) *cPlotArea {
} }
} }
// drawChartSeries provides function to draw the c:ser element by given format // drawChartSeries provides a function to draw the c:ser element by given
// sets. // format sets.
func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer { func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer {
ser := []cSer{} ser := []cSer{}
for k := range formatSet.Series { for k := range formatSet.Series {
@ -799,7 +799,7 @@ func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer {
return &ser return &ser
} }
// drawChartSeriesSpPr provides function to draw the c:spPr element by given // drawChartSeriesSpPr provides a function to draw the c:spPr element by given
// format sets. // format sets.
func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr { func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr {
spPrScatter := &cSpPr{ spPrScatter := &cSpPr{
@ -821,8 +821,8 @@ func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr {
return chartSeriesSpPr[formatSet.Type] return chartSeriesSpPr[formatSet.Type]
} }
// drawChartSeriesDPt provides function to draw the c:dPt element by given data // drawChartSeriesDPt provides a function to draw the c:dPt element by given
// index and format sets. // data index and format sets.
func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt { func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt {
dpt := []*cDPt{{ dpt := []*cDPt{{
IDx: &attrValInt{Val: i}, IDx: &attrValInt{Val: i},
@ -850,8 +850,8 @@ func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt {
return chartSeriesDPt[formatSet.Type] return chartSeriesDPt[formatSet.Type]
} }
// drawChartSeriesCat provides function to draw the c:cat element by given chart // drawChartSeriesCat provides a function to draw the c:cat element by given
// series and format sets. // chart series and format sets.
func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *cCat { func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *cCat {
cat := &cCat{ cat := &cCat{
StrRef: &cStrRef{ StrRef: &cStrRef{
@ -862,8 +862,8 @@ func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *
return chartSeriesCat[formatSet.Type] return chartSeriesCat[formatSet.Type]
} }
// drawChartSeriesVal provides function to draw the c:val element by given chart // drawChartSeriesVal provides a function to draw the c:val element by given
// series and format sets. // chart series and format sets.
func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *cVal { func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *cVal {
val := &cVal{ val := &cVal{
NumRef: &cNumRef{ NumRef: &cNumRef{
@ -874,8 +874,8 @@ func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *
return chartSeriesVal[formatSet.Type] return chartSeriesVal[formatSet.Type]
} }
// drawChartSeriesMarker provides function to draw the c:marker element by given // drawChartSeriesMarker provides a function to draw the c:marker element by
// data index and format sets. // given data index and format sets.
func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker { func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker {
marker := &cMarker{ marker := &cMarker{
Symbol: &attrValString{Val: "circle"}, Symbol: &attrValString{Val: "circle"},
@ -900,7 +900,7 @@ func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker {
return chartSeriesMarker[formatSet.Type] return chartSeriesMarker[formatSet.Type]
} }
// drawChartSeriesXVal provides function to draw the c:xVal element by given // drawChartSeriesXVal provides a function to draw the c:xVal element by given
// chart series and format sets. // chart series and format sets.
func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart) *cCat { func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart) *cCat {
cat := &cCat{ cat := &cCat{
@ -912,7 +912,7 @@ func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart)
return chartSeriesXVal[formatSet.Type] return chartSeriesXVal[formatSet.Type]
} }
// drawChartSeriesYVal provides function to draw the c:yVal element by given // drawChartSeriesYVal provides a function to draw the c:yVal element by given
// chart series and format sets. // chart series and format sets.
func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart) *cVal { func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart) *cVal {
val := &cVal{ val := &cVal{
@ -924,8 +924,8 @@ func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart)
return chartSeriesYVal[formatSet.Type] return chartSeriesYVal[formatSet.Type]
} }
// drawChartDLbls provides function to draw the c:dLbls element by given format // drawChartDLbls provides a function to draw the c:dLbls element by given
// sets. // format sets.
func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls { func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls {
return &cDLbls{ return &cDLbls{
ShowLegendKey: &attrValBool{Val: formatSet.Legend.ShowLegendKey}, ShowLegendKey: &attrValBool{Val: formatSet.Legend.ShowLegendKey},
@ -938,15 +938,15 @@ func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls {
} }
} }
// drawChartSeriesDLbls provides function to draw the c:dLbls element by given // drawChartSeriesDLbls provides a function to draw the c:dLbls element by
// format sets. // given format sets.
func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls { func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls {
dLbls := f.drawChartDLbls(formatSet) dLbls := f.drawChartDLbls(formatSet)
chartSeriesDLbls := map[string]*cDLbls{Bar: dLbls, BarStacked: dLbls, BarPercentStacked: dLbls, Bar3DClustered: dLbls, Bar3DStacked: dLbls, Bar3DPercentStacked: dLbls, Col: dLbls, ColStacked: dLbls, ColPercentStacked: dLbls, Col3DClustered: dLbls, Col3D: dLbls, Col3DStacked: dLbls, Col3DPercentStacked: dLbls, Doughnut: dLbls, Line: dLbls, Pie: dLbls, Pie3D: dLbls, Radar: dLbls, Scatter: nil} chartSeriesDLbls := map[string]*cDLbls{Bar: dLbls, BarStacked: dLbls, BarPercentStacked: dLbls, Bar3DClustered: dLbls, Bar3DStacked: dLbls, Bar3DPercentStacked: dLbls, Col: dLbls, ColStacked: dLbls, ColPercentStacked: dLbls, Col3DClustered: dLbls, Col3D: dLbls, Col3DStacked: dLbls, Col3DPercentStacked: dLbls, Doughnut: dLbls, Line: dLbls, Pie: dLbls, Pie3D: dLbls, Radar: dLbls, Scatter: nil}
return chartSeriesDLbls[formatSet.Type] return chartSeriesDLbls[formatSet.Type]
} }
// drawPlotAreaCatAx provides function to draw the c:catAx element. // drawPlotAreaCatAx provides a function to draw the c:catAx element.
func (f *File) drawPlotAreaCatAx(formatSet *formatChart) []*cAxs { func (f *File) drawPlotAreaCatAx(formatSet *formatChart) []*cAxs {
min := &attrValFloat{Val: formatSet.XAxis.Minimum} min := &attrValFloat{Val: formatSet.XAxis.Minimum}
max := &attrValFloat{Val: formatSet.XAxis.Maximum} max := &attrValFloat{Val: formatSet.XAxis.Maximum}
@ -985,7 +985,7 @@ func (f *File) drawPlotAreaCatAx(formatSet *formatChart) []*cAxs {
} }
} }
// drawPlotAreaValAx provides function to draw the c:valAx element. // drawPlotAreaValAx provides a function to draw the c:valAx element.
func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs { func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
min := &attrValFloat{Val: formatSet.YAxis.Minimum} min := &attrValFloat{Val: formatSet.YAxis.Minimum}
max := &attrValFloat{Val: formatSet.YAxis.Maximum} max := &attrValFloat{Val: formatSet.YAxis.Maximum}
@ -1021,7 +1021,7 @@ func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
} }
} }
// drawPlotAreaSpPr provides function to draw the c:spPr element. // drawPlotAreaSpPr provides a function to draw the c:spPr element.
func (f *File) drawPlotAreaSpPr() *cSpPr { func (f *File) drawPlotAreaSpPr() *cSpPr {
return &cSpPr{ return &cSpPr{
Ln: &aLn{ Ln: &aLn{
@ -1040,7 +1040,7 @@ func (f *File) drawPlotAreaSpPr() *cSpPr {
} }
} }
// drawPlotAreaTxPr provides function to draw the c:txPr element. // drawPlotAreaTxPr provides a function to draw the c:txPr element.
func (f *File) drawPlotAreaTxPr() *cTxPr { func (f *File) drawPlotAreaTxPr() *cTxPr {
return &cTxPr{ return &cTxPr{
BodyPr: aBodyPr{ BodyPr: aBodyPr{
@ -1079,8 +1079,8 @@ func (f *File) drawPlotAreaTxPr() *cTxPr {
} }
} }
// drawingParser provides function to parse drawingXML. In order to solve the // drawingParser provides a function to parse drawingXML. In order to solve
// problem that the label structure is changed after serialization and // the problem that the label structure is changed after serialization and
// deserialization, two different structures: decodeWsDr and encodeWsDr are // deserialization, two different structures: decodeWsDr and encodeWsDr are
// defined. // defined.
func (f *File) drawingParser(drawingXML string, content *xlsxWsDr) int { func (f *File) drawingParser(drawingXML string, content *xlsxWsDr) int {
@ -1107,8 +1107,8 @@ func (f *File) drawingParser(drawingXML string, content *xlsxWsDr) int {
return cNvPrID return cNvPrID
} }
// addDrawingChart provides function to add chart graphic frame by given sheet, // addDrawingChart provides a function to add chart graphic frame by given
// drawingXML, cell, width, height, relationship index and format sets. // sheet, drawingXML, cell, width, height, relationship index and format sets.
func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rID int, formatSet *formatPicture) { func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rID int, formatSet *formatPicture) {
cell = strings.ToUpper(cell) cell = strings.ToUpper(cell)
fromCol := string(strings.Map(letterOnlyMapF, cell)) fromCol := string(strings.Map(letterOnlyMapF, cell))

28
col.go
View File

@ -121,8 +121,8 @@ func (f *File) SetColOutlineLevel(sheet, column string, level uint8) {
xlsx.Cols.Col = append(xlsx.Cols.Col, col) xlsx.Cols.Col = append(xlsx.Cols.Col, col)
} }
// SetColWidth provides function to set the width of a single column or multiple // SetColWidth provides a function to set the width of a single column or
// columns. For example: // multiple columns. For example:
// //
// xlsx := excelize.NewFile() // xlsx := excelize.NewFile()
// xlsx.SetColWidth("Sheet1", "A", "H", 20) // xlsx.SetColWidth("Sheet1", "A", "H", 20)
@ -259,8 +259,8 @@ func (f *File) positionObjectPixels(sheet string, colStart, rowStart, x1, y1, wi
return colStart, rowStart, xAbs, yAbs, colEnd, rowEnd, x2, y2 return colStart, rowStart, xAbs, yAbs, colEnd, rowEnd, x2, y2
} }
// getColWidth provides function to get column width in pixels by given sheet // getColWidth provides a function to get column width in pixels by given
// name and column index. // sheet name and column index.
func (f *File) getColWidth(sheet string, col int) int { func (f *File) getColWidth(sheet string, col int) int {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
if xlsx.Cols != nil { if xlsx.Cols != nil {
@ -278,8 +278,8 @@ func (f *File) getColWidth(sheet string, col int) int {
return int(defaultColWidthPixels) return int(defaultColWidthPixels)
} }
// GetColWidth provides function to get column width by given worksheet name and // GetColWidth provides a function to get column width by given worksheet name
// column index. // and column index.
func (f *File) GetColWidth(sheet, column string) float64 { func (f *File) GetColWidth(sheet, column string) float64 {
col := TitleToNumber(strings.ToUpper(column)) + 1 col := TitleToNumber(strings.ToUpper(column)) + 1
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -298,8 +298,8 @@ func (f *File) GetColWidth(sheet, column string) float64 {
return defaultColWidthPixels return defaultColWidthPixels
} }
// InsertCol provides function to insert a new column before given column index. // InsertCol provides a function to insert a new column before given column
// For example, create a new column before column C in Sheet1: // index. For example, create a new column before column C in Sheet1:
// //
// xlsx.InsertCol("Sheet1", "C") // xlsx.InsertCol("Sheet1", "C")
// //
@ -308,8 +308,8 @@ func (f *File) InsertCol(sheet, column string) {
f.adjustHelper(sheet, col, -1, 1) f.adjustHelper(sheet, col, -1, 1)
} }
// RemoveCol provides function to remove single column by given worksheet name // RemoveCol provides a function to remove single column by given worksheet
// and column index. For example, remove column C in Sheet1: // name and column index. For example, remove column C in Sheet1:
// //
// xlsx.RemoveCol("Sheet1", "C") // xlsx.RemoveCol("Sheet1", "C")
// //
@ -346,10 +346,10 @@ func completeCol(xlsx *xlsxWorksheet, row, cell int) {
} }
} }
// convertColWidthToPixels provieds function to convert the width of a cell from // convertColWidthToPixels provieds function to convert the width of a cell
// user's units to pixels. Excel rounds the column width to the nearest pixel. // from user's units to pixels. Excel rounds the column width to the nearest
// If the width hasn't been set by the user we use the default value. If the // pixel. If the width hasn't been set by the user we use the default value.
// column is hidden it has a value of zero. // If the column is hidden it has a value of zero.
func convertColWidthToPixels(width float64) float64 { func convertColWidthToPixels(width float64) float64 {
var padding float64 = 5 var padding float64 = 5
var pixels float64 var pixels float64

View File

@ -8,8 +8,8 @@ import (
"strings" "strings"
) )
// parseFormatCommentsSet provides function to parse the format settings of the // parseFormatCommentsSet provides a function to parse the format settings of
// comment with default value. // the comment with default value.
func parseFormatCommentsSet(formatSet string) (*formatComment, error) { func parseFormatCommentsSet(formatSet string) (*formatComment, error) {
format := formatComment{ format := formatComment{
Author: "Author:", Author: "Author:",
@ -19,8 +19,8 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) {
return &format, err return &format, err
} }
// GetComments retrieves all comments and returns a map // GetComments retrieves all comments and returns a map of worksheet name to
// of worksheet name to the worksheet comments. // the worksheet comments.
func (f *File) GetComments() (comments map[string]*xlsxComments) { func (f *File) GetComments() (comments map[string]*xlsxComments) {
comments = map[string]*xlsxComments{} comments = map[string]*xlsxComments{}
for n := range f.sheetMap { for n := range f.sheetMap {
@ -81,7 +81,7 @@ func (f *File) AddComment(sheet, cell, format string) error {
return err return err
} }
// addDrawingVML provides function to create comment as // addDrawingVML provides a function to create comment as
// xl/drawings/vmlDrawing%d.vml by given commit ID and cell. // xl/drawings/vmlDrawing%d.vml by given commit ID and cell.
func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount, colCount int) { func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount, colCount int) {
col := string(strings.Map(letterOnlyMapF, cell)) col := string(strings.Map(letterOnlyMapF, cell))
@ -178,8 +178,8 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
f.XLSX[drawingVML] = v f.XLSX[drawingVML] = v
} }
// addComment provides function to create chart as xl/comments%d.xml by given // addComment provides a function to create chart as xl/comments%d.xml by
// cell and format sets. // given cell and format sets.
func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) { func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
a := formatSet.Author a := formatSet.Author
t := formatSet.Text t := formatSet.Text
@ -238,8 +238,8 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
f.saveFileList(commentsXML, v) f.saveFileList(commentsXML, v)
} }
// countComments provides function to get comments files count storage in the // countComments provides a function to get comments files count storage in
// folder xl. // the folder xl.
func (f *File) countComments() int { func (f *File) countComments() int {
count := 0 count := 0
for k := range f.XLSX { for k := range f.XLSX {

26
date.go
View File

@ -8,12 +8,12 @@ import (
// timeLocationUTC defined the UTC time location. // timeLocationUTC defined the UTC time location.
var timeLocationUTC, _ = time.LoadLocation("UTC") var timeLocationUTC, _ = time.LoadLocation("UTC")
// timeToUTCTime provides function to convert time to UTC time. // timeToUTCTime provides a function to convert time to UTC time.
func timeToUTCTime(t time.Time) time.Time { func timeToUTCTime(t time.Time) time.Time {
return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), timeLocationUTC) return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), timeLocationUTC)
} }
// timeToExcelTime provides function to convert time to Excel time. // timeToExcelTime provides a function to convert time to Excel time.
func timeToExcelTime(t time.Time) float64 { func timeToExcelTime(t time.Time) float64 {
// TODO in future this should probably also handle date1904 and like TimeFromExcelTime // TODO in future this should probably also handle date1904 and like TimeFromExcelTime
var excelTime float64 var excelTime float64
@ -32,7 +32,7 @@ func timeToExcelTime(t time.Time) float64 {
return excelTime + float64(t.UnixNano())/8.64e13 + 25569.0 return excelTime + float64(t.UnixNano())/8.64e13 + 25569.0
} }
// shiftJulianToNoon provides function to process julian date to noon. // shiftJulianToNoon provides a function to process julian date to noon.
func shiftJulianToNoon(julianDays, julianFraction float64) (float64, float64) { func shiftJulianToNoon(julianDays, julianFraction float64) (float64, float64) {
switch { switch {
case -0.5 < julianFraction && julianFraction < 0.5: case -0.5 < julianFraction && julianFraction < 0.5:
@ -47,7 +47,7 @@ func shiftJulianToNoon(julianDays, julianFraction float64) (float64, float64) {
return julianDays, julianFraction return julianDays, julianFraction
} }
// fractionOfADay provides function to return the integer values for hour, // fractionOfADay provides a function to return the integer values for hour,
// minutes, seconds and nanoseconds that comprised a given fraction of a day. // minutes, seconds and nanoseconds that comprised a given fraction of a day.
// values would round to 1 us. // values would round to 1 us.
func fractionOfADay(fraction float64) (hours, minutes, seconds, nanoseconds int) { func fractionOfADay(fraction float64) (hours, minutes, seconds, nanoseconds int) {
@ -68,7 +68,7 @@ func fractionOfADay(fraction float64) (hours, minutes, seconds, nanoseconds int)
return return
} }
// julianDateToGregorianTime provides function to convert julian date to // julianDateToGregorianTime provides a function to convert julian date to
// gregorian time. // gregorian time.
func julianDateToGregorianTime(part1, part2 float64) time.Time { func julianDateToGregorianTime(part1, part2 float64) time.Time {
part1I, part1F := math.Modf(part1) part1I, part1F := math.Modf(part1)
@ -81,12 +81,12 @@ func julianDateToGregorianTime(part1, part2 float64) time.Time {
return time.Date(year, time.Month(month), day, hours, minutes, seconds, nanoseconds, time.UTC) return time.Date(year, time.Month(month), day, hours, minutes, seconds, nanoseconds, time.UTC)
} }
// By this point generations of programmers have repeated the algorithm sent to // By this point generations of programmers have repeated the algorithm sent
// the editor of "Communications of the ACM" in 1968 (published in CACM, volume // to the editor of "Communications of the ACM" in 1968 (published in CACM,
// 11, number 10, October 1968, p.657). None of those programmers seems to have // volume 11, number 10, October 1968, p.657). None of those programmers seems
// found it necessary to explain the constants or variable names set out by // to have found it necessary to explain the constants or variable names set
// Henry F. Fliegel and Thomas C. Van Flandern. Maybe one day I'll buy that // out by Henry F. Fliegel and Thomas C. Van Flandern. Maybe one day I'll buy
// jounal and expand an explanation here - that day is not today. // that jounal and expand an explanation here - that day is not today.
func doTheFliegelAndVanFlandernAlgorithm(jd int) (day, month, year int) { func doTheFliegelAndVanFlandernAlgorithm(jd int) (day, month, year int) {
l := jd + 68569 l := jd + 68569
n := (4 * l) / 146097 n := (4 * l) / 146097
@ -101,8 +101,8 @@ func doTheFliegelAndVanFlandernAlgorithm(jd int) (day, month, year int) {
return d, m, y return d, m, y
} }
// timeFromExcelTime provides function to convert an excelTime representation // timeFromExcelTime provides a function to convert an excelTime
// (stored as a floating point number) to a time.Time. // representation (stored as a floating point number) to a time.Time.
func timeFromExcelTime(excelTime float64, date1904 bool) time.Time { func timeFromExcelTime(excelTime float64, date1904 bool) time.Time {
const MDD int64 = 106750 // Max time.Duration Days, aprox. 290 years const MDD int64 = 106750 // Max time.Duration Days, aprox. 290 years
var date time.Time var date time.Time

View File

@ -71,7 +71,7 @@ func OpenReader(r io.Reader) (*File, error) {
return f, nil return f, nil
} }
// setDefaultTimeStyle provides function to set default numbers format for // setDefaultTimeStyle provides a function to set default numbers format for
// time.Time type cell value by given worksheet name, cell coordinates and // time.Time type cell value by given worksheet name, cell coordinates and
// number format code. // number format code.
func (f *File) setDefaultTimeStyle(sheet, axis string, format int) { func (f *File) setDefaultTimeStyle(sheet, axis string, format int) {
@ -81,8 +81,8 @@ func (f *File) setDefaultTimeStyle(sheet, axis string, format int) {
} }
} }
// workSheetReader provides function to get the pointer to the structure after // workSheetReader provides a function to get the pointer to the structure
// deserialization by given worksheet name. // after deserialization by given worksheet name.
func (f *File) workSheetReader(sheet string) *xlsxWorksheet { func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
name, ok := f.sheetMap[trimSheetName(sheet)] name, ok := f.sheetMap[trimSheetName(sheet)]
if !ok { if !ok {
@ -105,7 +105,7 @@ func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
return f.Sheet[name] return f.Sheet[name]
} }
// checkSheet provides function to fill each row element and make that is // checkSheet provides a function to fill each row element and make that is
// continuous in a worksheet of XML. // continuous in a worksheet of XML.
func checkSheet(xlsx *xlsxWorksheet) { func checkSheet(xlsx *xlsxWorksheet) {
row := len(xlsx.SheetData.Row) row := len(xlsx.SheetData.Row)
@ -133,7 +133,7 @@ func checkSheet(xlsx *xlsxWorksheet) {
xlsx.SheetData = sheetData xlsx.SheetData = sheetData
} }
// replaceWorkSheetsRelationshipsNameSpaceBytes provides function to replace // replaceWorkSheetsRelationshipsNameSpaceBytes provides a function to replace
// xl/worksheets/sheet%d.xml XML tags to self-closing for compatible Microsoft // xl/worksheets/sheet%d.xml XML tags to self-closing for compatible Microsoft
// Office Excel 2007. // Office Excel 2007.
func replaceWorkSheetsRelationshipsNameSpaceBytes(workbookMarshal []byte) []byte { func replaceWorkSheetsRelationshipsNameSpaceBytes(workbookMarshal []byte) []byte {
@ -182,7 +182,7 @@ func (f *File) UpdateLinkedValue() {
} }
} }
// adjustHelper provides function to adjust rows and columns dimensions, // adjustHelper provides a function to adjust rows and columns dimensions,
// hyperlinks, merged cells and auto filter when inserting or deleting rows or // hyperlinks, merged cells and auto filter when inserting or deleting rows or
// columns. // columns.
// //
@ -204,7 +204,7 @@ func (f *File) adjustHelper(sheet string, column, row, offset int) {
checkRow(xlsx) checkRow(xlsx)
} }
// adjustColDimensions provides function to update column dimensions when // adjustColDimensions provides a function to update column dimensions when
// inserting or deleting rows or columns. // inserting or deleting rows or columns.
func (f *File) adjustColDimensions(xlsx *xlsxWorksheet, column, offset int) { func (f *File) adjustColDimensions(xlsx *xlsxWorksheet, column, offset int) {
for i, r := range xlsx.SheetData.Row { for i, r := range xlsx.SheetData.Row {
@ -220,8 +220,8 @@ func (f *File) adjustColDimensions(xlsx *xlsxWorksheet, column, offset int) {
} }
} }
// adjustRowDimensions provides function to update row dimensions when inserting // adjustRowDimensions provides a function to update row dimensions when
// or deleting rows or columns. // inserting or deleting rows or columns.
func (f *File) adjustRowDimensions(xlsx *xlsxWorksheet, rowIndex, offset int) { func (f *File) adjustRowDimensions(xlsx *xlsxWorksheet, rowIndex, offset int) {
if rowIndex == -1 { if rowIndex == -1 {
return return
@ -240,7 +240,7 @@ func (f *File) adjustRowDimensions(xlsx *xlsxWorksheet, rowIndex, offset int) {
} }
} }
// adjustHyperlinks provides function to update hyperlinks when inserting or // adjustHyperlinks provides a function to update hyperlinks when inserting or
// deleting rows or columns. // deleting rows or columns.
func (f *File) adjustHyperlinks(sheet string, column, rowIndex, offset int) { func (f *File) adjustHyperlinks(sheet string, column, rowIndex, offset int) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -280,8 +280,8 @@ func (f *File) adjustHyperlinks(sheet string, column, rowIndex, offset int) {
} }
} }
// adjustMergeCellsHelper provides function to update merged cells when inserting or // adjustMergeCellsHelper provides a function to update merged cells when
// deleting rows or columns. // inserting or deleting rows or columns.
func (f *File) adjustMergeCellsHelper(xlsx *xlsxWorksheet, column, rowIndex, offset int) { func (f *File) adjustMergeCellsHelper(xlsx *xlsxWorksheet, column, rowIndex, offset int) {
if xlsx.MergeCells != nil { if xlsx.MergeCells != nil {
for k, v := range xlsx.MergeCells.Cells { for k, v := range xlsx.MergeCells.Cells {
@ -321,8 +321,8 @@ func (f *File) adjustMergeCellsHelper(xlsx *xlsxWorksheet, column, rowIndex, off
} }
} }
// adjustMergeCells provides function to update merged cells when inserting or // adjustMergeCells provides a function to update merged cells when inserting
// deleting rows or columns. // or deleting rows or columns.
func (f *File) adjustMergeCells(xlsx *xlsxWorksheet, column, rowIndex, offset int) { func (f *File) adjustMergeCells(xlsx *xlsxWorksheet, column, rowIndex, offset int) {
f.adjustMergeCellsHelper(xlsx, column, rowIndex, offset) f.adjustMergeCellsHelper(xlsx, column, rowIndex, offset)
@ -342,8 +342,8 @@ func (f *File) adjustMergeCells(xlsx *xlsxWorksheet, column, rowIndex, offset in
} }
} }
// adjustAutoFilter provides function to update the auto filter when inserting // adjustAutoFilter provides a function to update the auto filter when
// or deleting rows or columns. // inserting or deleting rows or columns.
func (f *File) adjustAutoFilter(xlsx *xlsxWorksheet, column, rowIndex, offset int) { func (f *File) adjustAutoFilter(xlsx *xlsxWorksheet, column, rowIndex, offset int) {
f.adjustAutoFilterHelper(xlsx, column, rowIndex, offset) f.adjustAutoFilterHelper(xlsx, column, rowIndex, offset)
@ -376,7 +376,7 @@ func (f *File) adjustAutoFilter(xlsx *xlsxWorksheet, column, rowIndex, offset in
} }
} }
// adjustAutoFilterHelper provides function to update the auto filter when // adjustAutoFilterHelper provides a function to update the auto filter when
// inserting or deleting rows or columns. // inserting or deleting rows or columns.
func (f *File) adjustAutoFilterHelper(xlsx *xlsxWorksheet, column, rowIndex, offset int) { func (f *File) adjustAutoFilterHelper(xlsx *xlsxWorksheet, column, rowIndex, offset int) {
if xlsx.AutoFilter != nil { if xlsx.AutoFilter != nil {

10
file.go
View File

@ -8,7 +8,7 @@ import (
"os" "os"
) )
// NewFile provides function to create new file by default template. For // NewFile provides a function to create new file by default template. For
// example: // example:
// //
// xlsx := NewFile() // xlsx := NewFile()
@ -40,7 +40,7 @@ func NewFile() *File {
return f return f
} }
// Save provides function to override the xlsx file with origin path. // Save provides a function to override the xlsx file with origin path.
func (f *File) Save() error { func (f *File) Save() error {
if f.Path == "" { if f.Path == "" {
return fmt.Errorf("No path defined for file, consider File.WriteTo or File.Write") return fmt.Errorf("No path defined for file, consider File.WriteTo or File.Write")
@ -48,8 +48,8 @@ func (f *File) Save() error {
return f.SaveAs(f.Path) return f.SaveAs(f.Path)
} }
// SaveAs provides function to create or update to an xlsx file at the provided // SaveAs provides a function to create or update to an xlsx file at the
// path. // provided path.
func (f *File) SaveAs(name string) error { func (f *File) SaveAs(name string) error {
file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666) file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
if err != nil { if err != nil {
@ -59,7 +59,7 @@ func (f *File) SaveAs(name string) error {
return f.Write(file) return f.Write(file)
} }
// Write provides function to write to an io.Writer. // Write provides a function to write to an io.Writer.
func (f *File) Write(w io.Writer) error { func (f *File) Write(w io.Writer) error {
_, err := f.WriteTo(w) _, err := f.WriteTo(w)
return err return err

21
lib.go
View File

@ -25,7 +25,7 @@ func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) {
return fileList, worksheets, nil return fileList, worksheets, nil
} }
// readXML provides function to read XML content as string. // readXML provides a function to read XML content as string.
func (f *File) readXML(name string) []byte { func (f *File) readXML(name string) []byte {
if content, ok := f.XLSX[name]; ok { if content, ok := f.XLSX[name]; ok {
return content return content
@ -33,8 +33,8 @@ func (f *File) readXML(name string) []byte {
return []byte{} return []byte{}
} }
// saveFileList provides function to update given file content in file list of // saveFileList provides a function to update given file content in file list
// XLSX. // of XLSX.
func (f *File) saveFileList(name string, content []byte) { func (f *File) saveFileList(name string, content []byte) {
newContent := make([]byte, 0, len(XMLHeader)+len(content)) newContent := make([]byte, 0, len(XMLHeader)+len(content))
newContent = append(newContent, []byte(XMLHeader)...) newContent = append(newContent, []byte(XMLHeader)...)
@ -54,7 +54,7 @@ func readFile(file *zip.File) []byte {
return buff.Bytes() return buff.Bytes()
} }
// ToAlphaString provides function to convert integer to Excel sheet column // ToAlphaString provides a function to convert integer to Excel sheet column
// title. For example convert 36 to column title AK: // title. For example convert 36 to column title AK:
// //
// excelize.ToAlphaString(36) // excelize.ToAlphaString(36)
@ -72,9 +72,9 @@ func ToAlphaString(value int) string {
return ans return ans
} }
// TitleToNumber provides function to convert Excel sheet column title to int // TitleToNumber provides a function to convert Excel sheet column title to
// (this function doesn't do value check currently). For example convert AK // int (this function doesn't do value check currently). For example convert
// and ak to column title 36: // AK and ak to column title 36:
// //
// excelize.TitleToNumber("AK") // excelize.TitleToNumber("AK")
// excelize.TitleToNumber("ak") // excelize.TitleToNumber("ak")
@ -125,8 +125,8 @@ func defaultTrue(b *bool) bool {
return *b return *b
} }
// axisLowerOrEqualThan returns true if axis1 <= axis2 // axisLowerOrEqualThan returns true if axis1 <= axis2 axis1/axis2 can be
// axis1/axis2 can be either a column or a row axis, e.g. "A", "AAE", "42", "1", etc. // either a column or a row axis, e.g. "A", "AAE", "42", "1", etc.
// //
// For instance, the following comparisons are all true: // For instance, the following comparisons are all true:
// //
@ -147,7 +147,8 @@ func axisLowerOrEqualThan(axis1, axis2 string) bool {
} }
} }
// getCellColRow returns the two parts of a cell identifier (its col and row) as strings // getCellColRow returns the two parts of a cell identifier (its col and row)
// as strings
// //
// For instance: // For instance:
// //

View File

@ -14,8 +14,8 @@ import (
"strings" "strings"
) )
// parseFormatPictureSet provides function to parse the format settings of the // parseFormatPictureSet provides a function to parse the format settings of
// picture with default value. // the picture with default value.
func parseFormatPictureSet(formatSet string) (*formatPicture, error) { func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
format := formatPicture{ format := formatPicture{
FPrintsWithSheet: true, FPrintsWithSheet: true,
@ -116,7 +116,7 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
return err return err
} }
// addSheetRelationships provides function to add // addSheetRelationships provides a function to add
// xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name, relationship // xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name, relationship
// type and target. // type and target.
func (f *File) addSheetRelationships(sheet, relType, target, targetMode string) int { func (f *File) addSheetRelationships(sheet, relType, target, targetMode string) int {
@ -149,9 +149,9 @@ func (f *File) addSheetRelationships(sheet, relType, target, targetMode string)
return rID return rID
} }
// deleteSheetRelationships provides function to delete relationships in // deleteSheetRelationships provides a function to delete relationships in
// xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and relationship // xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and
// index. // relationship index.
func (f *File) deleteSheetRelationships(sheet, rID string) { func (f *File) deleteSheetRelationships(sheet, rID string) {
name, ok := f.sheetMap[trimSheetName(sheet)] name, ok := f.sheetMap[trimSheetName(sheet)]
if !ok { if !ok {
@ -169,7 +169,7 @@ func (f *File) deleteSheetRelationships(sheet, rID string) {
f.saveFileList(rels, output) f.saveFileList(rels, output)
} }
// addSheetLegacyDrawing provides function to add legacy drawing element to // addSheetLegacyDrawing provides a function to add legacy drawing element to
// xl/worksheets/sheet%d.xml by given worksheet name and relationship index. // xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
func (f *File) addSheetLegacyDrawing(sheet string, rID int) { func (f *File) addSheetLegacyDrawing(sheet string, rID int) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -178,7 +178,7 @@ func (f *File) addSheetLegacyDrawing(sheet string, rID int) {
} }
} }
// addSheetDrawing provides function to add drawing element to // addSheetDrawing provides a function to add drawing element to
// xl/worksheets/sheet%d.xml by given worksheet name and relationship index. // xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
func (f *File) addSheetDrawing(sheet string, rID int) { func (f *File) addSheetDrawing(sheet string, rID int) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -187,7 +187,7 @@ func (f *File) addSheetDrawing(sheet string, rID int) {
} }
} }
// addSheetPicture provides function to add picture element to // addSheetPicture provides a function to add picture element to
// xl/worksheets/sheet%d.xml by given worksheet name and relationship index. // xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
func (f *File) addSheetPicture(sheet string, rID int) { func (f *File) addSheetPicture(sheet string, rID int) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -196,7 +196,7 @@ func (f *File) addSheetPicture(sheet string, rID int) {
} }
} }
// countDrawings provides function to get drawing files count storage in the // countDrawings provides a function to get drawing files count storage in the
// folder xl/drawings. // folder xl/drawings.
func (f *File) countDrawings() int { func (f *File) countDrawings() int {
count := 0 count := 0
@ -208,7 +208,7 @@ func (f *File) countDrawings() int {
return count return count
} }
// addDrawingPicture provides function to add picture by given sheet, // addDrawingPicture provides a function to add picture by given sheet,
// drawingXML, cell, file name, width, height relationship index and format // drawingXML, cell, file name, width, height relationship index and format
// sets. // sets.
func (f *File) addDrawingPicture(sheet, drawingXML, cell, file string, width, height, rID, hyperlinkRID int, formatSet *formatPicture) { func (f *File) addDrawingPicture(sheet, drawingXML, cell, file string, width, height, rID, hyperlinkRID int, formatSet *formatPicture) {
@ -263,8 +263,8 @@ func (f *File) addDrawingPicture(sheet, drawingXML, cell, file string, width, he
f.saveFileList(drawingXML, output) f.saveFileList(drawingXML, output)
} }
// addDrawingRelationships provides function to add image part relationships in // addDrawingRelationships provides a function to add image part relationships
// the file xl/drawings/_rels/drawing%d.xml.rels by given drawing index, // in the file xl/drawings/_rels/drawing%d.xml.rels by given drawing index,
// relationship type and target. // relationship type and target.
func (f *File) addDrawingRelationships(index int, relType, target, targetMode string) int { func (f *File) addDrawingRelationships(index int, relType, target, targetMode string) int {
var rels = "xl/drawings/_rels/drawing" + strconv.Itoa(index) + ".xml.rels" var rels = "xl/drawings/_rels/drawing" + strconv.Itoa(index) + ".xml.rels"
@ -292,8 +292,8 @@ func (f *File) addDrawingRelationships(index int, relType, target, targetMode st
return rID return rID
} }
// countMedia provides function to get media files count storage in the folder // countMedia provides a function to get media files count storage in the
// xl/media/image. // folder xl/media/image.
func (f *File) countMedia() int { func (f *File) countMedia() int {
count := 0 count := 0
for k := range f.XLSX { for k := range f.XLSX {
@ -304,8 +304,8 @@ func (f *File) countMedia() int {
return count return count
} }
// addMedia provides function to add picture into folder xl/media/image by given // addMedia provides a function to add picture into folder xl/media/image by
// file name and extension name. // given file name and extension name.
func (f *File) addMedia(file, ext string) { func (f *File) addMedia(file, ext string) {
count := f.countMedia() count := f.countMedia()
dat, _ := ioutil.ReadFile(file) dat, _ := ioutil.ReadFile(file)
@ -313,8 +313,8 @@ func (f *File) addMedia(file, ext string) {
f.XLSX[media] = dat f.XLSX[media] = dat
} }
// setContentTypePartImageExtensions provides function to set the content type // setContentTypePartImageExtensions provides a function to set the content
// for relationship parts and the Main Document part. // type for relationship parts and the Main Document part.
func (f *File) setContentTypePartImageExtensions() { func (f *File) setContentTypePartImageExtensions() {
var imageTypes = map[string]bool{"jpeg": false, "png": false, "gif": false} var imageTypes = map[string]bool{"jpeg": false, "png": false, "gif": false}
content := f.contentTypesReader() content := f.contentTypesReader()
@ -334,7 +334,7 @@ func (f *File) setContentTypePartImageExtensions() {
} }
} }
// setContentTypePartVMLExtensions provides function to set the content type // setContentTypePartVMLExtensions provides a function to set the content type
// for relationship parts and the Main Document part. // for relationship parts and the Main Document part.
func (f *File) setContentTypePartVMLExtensions() { func (f *File) setContentTypePartVMLExtensions() {
vml := false vml := false
@ -352,8 +352,8 @@ func (f *File) setContentTypePartVMLExtensions() {
} }
} }
// addContentTypePart provides function to add content type part relationships // addContentTypePart provides a function to add content type part
// in the file [Content_Types].xml by given index. // relationships in the file [Content_Types].xml by given index.
func (f *File) addContentTypePart(index int, contentType string) { func (f *File) addContentTypePart(index int, contentType string) {
setContentType := map[string]func(){ setContentType := map[string]func(){
"comments": f.setContentTypePartVMLExtensions, "comments": f.setContentTypePartVMLExtensions,
@ -387,7 +387,7 @@ func (f *File) addContentTypePart(index int, contentType string) {
}) })
} }
// getSheetRelationshipsTargetByID provides function to get Target attribute // getSheetRelationshipsTargetByID provides a function to get Target attribute
// value in xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and // value in xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and
// relationship index. // relationship index.
func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string { func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
@ -406,9 +406,9 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
return "" return ""
} }
// GetPicture provides function to get picture base name and raw content embed // GetPicture provides a function to get picture base name and raw content
// in XLSX by given worksheet and cell name. This function returns the file name // embed in XLSX by given worksheet and cell name. This function returns the
// in XLSX and file contents as []byte data types. For example: // file name in XLSX and file contents as []byte data types. For example:
// //
// xlsx, err := excelize.OpenFile("./Book1.xlsx") // xlsx, err := excelize.OpenFile("./Book1.xlsx")
// if err != nil { // if err != nil {
@ -463,8 +463,9 @@ func (f *File) GetPicture(sheet, cell string) (string, []byte) {
return "", []byte{} return "", []byte{}
} }
// getDrawingRelationships provides function to get drawing relationships from // getDrawingRelationships provides a function to get drawing relationships
// xl/drawings/_rels/drawing%s.xml.rels by given file name and relationship ID. // from xl/drawings/_rels/drawing%s.xml.rels by given file name and
// relationship ID.
func (f *File) getDrawingRelationships(rels, rID string) *xlsxWorkbookRelation { func (f *File) getDrawingRelationships(rels, rID string) *xlsxWorkbookRelation {
_, ok := f.XLSX[rels] _, ok := f.XLSX[rels]
if !ok { if !ok {

39
rows.go
View File

@ -132,7 +132,7 @@ func (err ErrSheetNotExist) Error() string {
// Rows return a rows iterator. For example: // Rows return a rows iterator. For example:
// //
// rows, err := xlsx.GetRows("Sheet1") // rows, err := xlsx.Rows("Sheet1")
// for rows.Next() { // for rows.Next() {
// for _, colCell := range rows.Columns() { // for _, colCell := range rows.Columns() {
// fmt.Print(colCell, "\t") // fmt.Print(colCell, "\t")
@ -202,7 +202,7 @@ func (f *File) SetRowHeight(sheet string, row int, height float64) {
xlsx.SheetData.Row[rowIdx].CustomHeight = true xlsx.SheetData.Row[rowIdx].CustomHeight = true
} }
// getRowHeight provides function to get row height in pixels by given sheet // getRowHeight provides a function to get row height in pixels by given sheet
// name and row index. // name and row index.
func (f *File) getRowHeight(sheet string, row int) int { func (f *File) getRowHeight(sheet string, row int) int {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -215,7 +215,7 @@ func (f *File) getRowHeight(sheet string, row int) int {
return int(defaultRowHeightPixels) return int(defaultRowHeightPixels)
} }
// GetRowHeight provides function to get row height by given worksheet name // GetRowHeight provides a function to get row height by given worksheet name
// and row index. For example, get the height of the first row in Sheet1: // and row index. For example, get the height of the first row in Sheet1:
// //
// xlsx.GetRowHeight("Sheet1", 1) // xlsx.GetRowHeight("Sheet1", 1)
@ -231,7 +231,7 @@ func (f *File) GetRowHeight(sheet string, row int) float64 {
return defaultRowHeightPixels return defaultRowHeightPixels
} }
// sharedStringsReader provides function to get the pointer to the structure // sharedStringsReader provides a function to get the pointer to the structure
// after deserialization of xl/sharedStrings.xml. // after deserialization of xl/sharedStrings.xml.
func (f *File) sharedStringsReader() *xlsxSST { func (f *File) sharedStringsReader() *xlsxSST {
if f.SharedStrings == nil { if f.SharedStrings == nil {
@ -246,8 +246,9 @@ func (f *File) sharedStringsReader() *xlsxSST {
return f.SharedStrings return f.SharedStrings
} }
// getValueFrom return a value from a column/row cell, this function is inteded // getValueFrom return a value from a column/row cell, this function is
// to be used with for range on rows an argument with the xlsx opened file. // inteded to be used with for range on rows an argument with the xlsx opened
// file.
func (xlsx *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) { func (xlsx *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) {
switch xlsx.T { switch xlsx.T {
case "s": case "s":
@ -315,9 +316,9 @@ func (f *File) SetRowOutlineLevel(sheet string, rowIndex int, level uint8) {
xlsx.SheetData.Row[rowIndex].OutlineLevel = level xlsx.SheetData.Row[rowIndex].OutlineLevel = level
} }
// GetRowOutlineLevel provides a function to get outline level number of a single row by given // GetRowOutlineLevel provides a function to get outline level number of a
// worksheet name and row index. For example, get outline number of row 2 in // single row by given worksheet name and row index. For example, get outline
// Sheet1: // number of row 2 in Sheet1:
// //
// xlsx.GetRowOutlineLevel("Sheet1", 2) // xlsx.GetRowOutlineLevel("Sheet1", 2)
// //
@ -329,8 +330,8 @@ func (f *File) GetRowOutlineLevel(sheet string, rowIndex int) uint8 {
return xlsx.SheetData.Row[rowIndex].OutlineLevel return xlsx.SheetData.Row[rowIndex].OutlineLevel
} }
// RemoveRow provides function to remove single row by given worksheet name and // RemoveRow provides a function to remove single row by given worksheet name
// row index. For example, remove row 3 in Sheet1: // and row index. For example, remove row 3 in Sheet1:
// //
// xlsx.RemoveRow("Sheet1", 2) // xlsx.RemoveRow("Sheet1", 2)
// //
@ -349,8 +350,8 @@ func (f *File) RemoveRow(sheet string, row int) {
} }
} }
// InsertRow provides function to insert a new row before given row index. For // InsertRow provides a function to insert a new row before given row index.
// example, create a new row before row 3 in Sheet1: // For example, create a new row before row 3 in Sheet1:
// //
// xlsx.InsertRow("Sheet1", 2) // xlsx.InsertRow("Sheet1", 2)
// //
@ -362,8 +363,8 @@ func (f *File) InsertRow(sheet string, row int) {
f.adjustHelper(sheet, -1, row, 1) f.adjustHelper(sheet, -1, row, 1)
} }
// checkRow provides function to check and fill each column element for all rows // checkRow provides a function to check and fill each column element for all
// and make that is continuous in a worksheet of XML. For example: // rows and make that is continuous in a worksheet of XML. For example:
// //
// <row r="15" spans="1:22" x14ac:dyDescent="0.2"> // <row r="15" spans="1:22" x14ac:dyDescent="0.2">
// <c r="A15" s="2" /> // <c r="A15" s="2" />
@ -416,7 +417,7 @@ func checkRow(xlsx *xlsxWorksheet) {
} }
} }
// completeRow provides function to check and fill each column element for a // completeRow provides a function to check and fill each column element for a
// single row and make that is continuous in a worksheet of XML by given row // single row and make that is continuous in a worksheet of XML by given row
// index and axis. // index and axis.
func completeRow(xlsx *xlsxWorksheet, row, cell int) { func completeRow(xlsx *xlsxWorksheet, row, cell int) {
@ -448,9 +449,9 @@ func completeRow(xlsx *xlsxWorksheet, row, cell int) {
} }
} }
// convertRowHeightToPixels provides function to convert the height of a cell // convertRowHeightToPixels provides a function to convert the height of a
// from user's units to pixels. If the height hasn't been set by the user we use // cell from user's units to pixels. If the height hasn't been set by the user
// the default value. If the row is hidden it has a value of zero. // we use the default value. If the row is hidden it has a value of zero.
func convertRowHeightToPixels(height float64) float64 { func convertRowHeightToPixels(height float64) float64 {
var pixels float64 var pixels float64
if height == 0 { if height == 0 {

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
// parseFormatShapeSet provides function to parse the format settings of the // parseFormatShapeSet provides a function to parse the format settings of the
// shape with default value. // shape with default value.
func parseFormatShapeSet(formatSet string) (*formatShape, error) { func parseFormatShapeSet(formatSet string) (*formatShape, error) {
format := formatShape{ format := formatShape{
@ -29,8 +29,8 @@ func parseFormatShapeSet(formatSet string) (*formatShape, error) {
// AddShape provides the method to add shape in a sheet by given worksheet // 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 // index, shape format set (such as offset, scale, aspect ratio setting and
// print settings) and properties set. For example, add text box (rect shape) in // print settings) and properties set. For example, add text box (rect shape)
// Sheet1: // in Sheet1:
// //
// xlsx.AddShape("Sheet1", "G6", `{"type":"rect","color":{"line":"#4286F4","fill":"#8eb9ff"},"paragraph":[{"text":"Rectangle Shape","font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"sng"}}],"width":180,"height": 90}`) // xlsx.AddShape("Sheet1", "G6", `{"type":"rect","color":{"line":"#4286F4","fill":"#8eb9ff"},"paragraph":[{"text":"Rectangle Shape","font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"sng"}}],"width":180,"height": 90}`)
// //
@ -272,7 +272,7 @@ func (f *File) AddShape(sheet, cell, format string) error {
return err return err
} }
// addDrawingShape provides function to add preset geometry by given sheet, // addDrawingShape provides a function to add preset geometry by given sheet,
// drawingXMLand format sets. // drawingXMLand format sets.
func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *formatShape) { func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *formatShape) {
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} 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}
@ -397,7 +397,7 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *format
f.saveFileList(drawingXML, output) f.saveFileList(drawingXML, output)
} }
// setShapeRef provides function to set color with hex model by given actual // setShapeRef provides a function to set color with hex model by given actual
// color value. // color value.
func setShapeRef(color string, i int) *aRef { func setShapeRef(color string, i int) *aRef {
if color == "" { if color == "" {

View File

@ -14,7 +14,7 @@ import (
"github.com/mohae/deepcopy" "github.com/mohae/deepcopy"
) )
// NewSheet provides function to create a new sheet by given worksheet name, // NewSheet provides a function to create a new sheet by given worksheet name,
// when creating a new XLSX file, the default sheet will be create, when you // when creating a new XLSX file, the default sheet will be create, when you
// create a new file. // create a new file.
func (f *File) NewSheet(name string) int { func (f *File) NewSheet(name string) int {
@ -36,7 +36,7 @@ func (f *File) NewSheet(name string) int {
return f.SheetCount return f.SheetCount
} }
// contentTypesReader provides function to get the pointer to the // contentTypesReader provides a function to get the pointer to the
// [Content_Types].xml structure after deserialization. // [Content_Types].xml structure after deserialization.
func (f *File) contentTypesReader() *xlsxTypes { func (f *File) contentTypesReader() *xlsxTypes {
if f.ContentTypes == nil { if f.ContentTypes == nil {
@ -47,7 +47,7 @@ func (f *File) contentTypesReader() *xlsxTypes {
return f.ContentTypes return f.ContentTypes
} }
// contentTypesWriter provides function to save [Content_Types].xml after // contentTypesWriter provides a function to save [Content_Types].xml after
// serialize structure. // serialize structure.
func (f *File) contentTypesWriter() { func (f *File) contentTypesWriter() {
if f.ContentTypes != nil { if f.ContentTypes != nil {
@ -56,7 +56,7 @@ func (f *File) contentTypesWriter() {
} }
} }
// workbookReader provides function to get the pointer to the xl/workbook.xml // workbookReader provides a function to get the pointer to the xl/workbook.xml
// structure after deserialization. // structure after deserialization.
func (f *File) workbookReader() *xlsxWorkbook { func (f *File) workbookReader() *xlsxWorkbook {
if f.WorkBook == nil { if f.WorkBook == nil {
@ -67,7 +67,7 @@ func (f *File) workbookReader() *xlsxWorkbook {
return f.WorkBook return f.WorkBook
} }
// workbookWriter provides function to save xl/workbook.xml after serialize // workbookWriter provides a function to save xl/workbook.xml after serialize
// structure. // structure.
func (f *File) workbookWriter() { func (f *File) workbookWriter() {
if f.WorkBook != nil { if f.WorkBook != nil {
@ -76,7 +76,7 @@ func (f *File) workbookWriter() {
} }
} }
// worksheetWriter provides function to save xl/worksheets/sheet%d.xml after // worksheetWriter provides a function to save xl/worksheets/sheet%d.xml after
// serialize structure. // serialize structure.
func (f *File) worksheetWriter() { func (f *File) worksheetWriter() {
for path, sheet := range f.Sheet { for path, sheet := range f.Sheet {
@ -94,7 +94,7 @@ func (f *File) worksheetWriter() {
} }
} }
// trimCell provides function to trim blank cells which created by completeCol. // trimCell provides a function to trim blank cells which created by completeCol.
func trimCell(column []xlsxC) []xlsxC { func trimCell(column []xlsxC) []xlsxC {
col := make([]xlsxC, len(column)) col := make([]xlsxC, len(column))
i := 0 i := 0
@ -147,7 +147,7 @@ func (f *File) setWorkbook(name string, rid int) {
}) })
} }
// workbookRelsReader provides function to read and unmarshal workbook // workbookRelsReader provides a function to read and unmarshal workbook
// relationships of XLSX file. // relationships of XLSX file.
func (f *File) workbookRelsReader() *xlsxWorkbookRels { func (f *File) workbookRelsReader() *xlsxWorkbookRels {
if f.WorkBookRels == nil { if f.WorkBookRels == nil {
@ -158,7 +158,7 @@ func (f *File) workbookRelsReader() *xlsxWorkbookRels {
return f.WorkBookRels return f.WorkBookRels
} }
// workbookRelsWriter provides function to save xl/_rels/workbook.xml.rels after // workbookRelsWriter provides a function to save xl/_rels/workbook.xml.rels after
// serialize structure. // serialize structure.
func (f *File) workbookRelsWriter() { func (f *File) workbookRelsWriter() {
if f.WorkBookRels != nil { if f.WorkBookRels != nil {
@ -211,7 +211,7 @@ func replaceRelationshipsNameSpaceBytes(workbookMarshal []byte) []byte {
return bytes.Replace(workbookMarshal, oldXmlns, newXmlns, -1) return bytes.Replace(workbookMarshal, oldXmlns, newXmlns, -1)
} }
// SetActiveSheet provides function to set default active worksheet of XLSX by // SetActiveSheet provides a function to set default active worksheet of XLSX by
// given index. Note that active index is different with the index that got by // given index. Note that active index is different with the index that got by
// function GetSheetMap, and it should be greater than 0 and less than total // function GetSheetMap, and it should be greater than 0 and less than total
// worksheet numbers. // worksheet numbers.
@ -247,7 +247,7 @@ func (f *File) SetActiveSheet(index int) {
} }
} }
// GetActiveSheetIndex provides function to get active sheet of XLSX. If not // GetActiveSheetIndex provides a function to get active sheet of XLSX. If not
// found the active sheet will be return integer 0. // found the active sheet will be return integer 0.
func (f *File) GetActiveSheetIndex() int { func (f *File) GetActiveSheetIndex() int {
buffer := bytes.Buffer{} buffer := bytes.Buffer{}
@ -269,7 +269,7 @@ func (f *File) GetActiveSheetIndex() int {
return 0 return 0
} }
// SetSheetName provides function to set the worksheet name be given old and new // SetSheetName provides a function to set the worksheet name be given old and new
// worksheet name. Maximum 31 characters are allowed in sheet title and this // worksheet name. Maximum 31 characters are allowed in sheet title and this
// function only changes the name of the sheet and will not update the sheet // function only changes the name of the sheet and will not update the sheet
// name in the formula or reference associated with the cell. So there may be // name in the formula or reference associated with the cell. So there may be
@ -287,7 +287,7 @@ func (f *File) SetSheetName(oldName, newName string) {
} }
} }
// GetSheetName provides function to get worksheet name of XLSX by given // GetSheetName provides a function to get worksheet name of XLSX by given
// worksheet index. If given sheet index is invalid, will return an empty // worksheet index. If given sheet index is invalid, will return an empty
// string. // string.
func (f *File) GetSheetName(index int) string { func (f *File) GetSheetName(index int) string {
@ -306,7 +306,7 @@ func (f *File) GetSheetName(index int) string {
return "" return ""
} }
// GetSheetIndex provides function to get worksheet index of XLSX by given sheet // GetSheetIndex provides a function to get worksheet index of XLSX by given sheet
// name. If given worksheet name is invalid, will return an integer type value // name. If given worksheet name is invalid, will return an integer type value
// 0. // 0.
func (f *File) GetSheetIndex(name string) int { func (f *File) GetSheetIndex(name string) int {
@ -325,7 +325,7 @@ func (f *File) GetSheetIndex(name string) int {
return 0 return 0
} }
// GetSheetMap provides function to get worksheet name and index map of XLSX. // GetSheetMap provides a function to get worksheet name and index map of XLSX.
// For example: // For example:
// //
// xlsx, err := excelize.OpenFile("./Book1.xlsx") // xlsx, err := excelize.OpenFile("./Book1.xlsx")
@ -351,7 +351,7 @@ func (f *File) GetSheetMap() map[int]string {
return sheetMap return sheetMap
} }
// getSheetMap provides function to get worksheet name and XML file path map of // getSheetMap provides a function to get worksheet name and XML file path map of
// XLSX. // XLSX.
func (f *File) getSheetMap() map[string]string { func (f *File) getSheetMap() map[string]string {
maps := make(map[string]string) maps := make(map[string]string)
@ -361,7 +361,7 @@ func (f *File) getSheetMap() map[string]string {
return maps return maps
} }
// SetSheetBackground provides function to set background picture by given // SetSheetBackground provides a function to set background picture by given
// worksheet name. // worksheet name.
func (f *File) SetSheetBackground(sheet, picture string) error { func (f *File) SetSheetBackground(sheet, picture string) error {
var err error var err error
@ -381,7 +381,7 @@ func (f *File) SetSheetBackground(sheet, picture string) error {
return err return err
} }
// DeleteSheet provides function to delete worksheet in a workbook by given // DeleteSheet provides a function to delete worksheet in a workbook by given
// worksheet name. Use this method with caution, which will affect changes in // worksheet name. Use this method with caution, which will affect changes in
// references such as formulas, charts, and so on. If there is any referenced // references such as formulas, charts, and so on. If there is any referenced
// value of the deleted worksheet, it will cause a file error when you open it. // value of the deleted worksheet, it will cause a file error when you open it.
@ -405,7 +405,7 @@ func (f *File) DeleteSheet(name string) {
f.SetActiveSheet(len(f.GetSheetMap())) f.SetActiveSheet(len(f.GetSheetMap()))
} }
// deleteSheetFromWorkbookRels provides function to remove worksheet // deleteSheetFromWorkbookRels provides a function to remove worksheet
// relationships by given relationships ID in the file // relationships by given relationships ID in the file
// xl/_rels/workbook.xml.rels. // xl/_rels/workbook.xml.rels.
func (f *File) deleteSheetFromWorkbookRels(rID string) string { func (f *File) deleteSheetFromWorkbookRels(rID string) string {
@ -419,7 +419,7 @@ func (f *File) deleteSheetFromWorkbookRels(rID string) string {
return "" return ""
} }
// deleteSheetFromContentTypes provides function to remove worksheet // deleteSheetFromContentTypes provides a function to remove worksheet
// relationships by given target name in the file [Content_Types].xml. // relationships by given target name in the file [Content_Types].xml.
func (f *File) deleteSheetFromContentTypes(target string) { func (f *File) deleteSheetFromContentTypes(target string) {
content := f.contentTypesReader() content := f.contentTypesReader()
@ -430,7 +430,7 @@ func (f *File) deleteSheetFromContentTypes(target string) {
} }
} }
// CopySheet provides function to duplicate a worksheet by gave source and // CopySheet provides a function to duplicate a worksheet by gave source and
// target worksheet index. Note that currently doesn't support duplicate // target worksheet index. Note that currently doesn't support duplicate
// workbooks that contain tables, charts or pictures. For Example: // workbooks that contain tables, charts or pictures. For Example:
// //
@ -447,7 +447,7 @@ func (f *File) CopySheet(from, to int) error {
return nil return nil
} }
// copySheet provides function to duplicate a worksheet by gave source and // copySheet provides a function to duplicate a worksheet by gave source and
// target worksheet name. // target worksheet name.
func (f *File) copySheet(from, to int) { func (f *File) copySheet(from, to int) {
sheet := f.workSheetReader("sheet" + strconv.Itoa(from)) sheet := f.workSheetReader("sheet" + strconv.Itoa(from))
@ -468,7 +468,7 @@ func (f *File) copySheet(from, to int) {
} }
} }
// SetSheetVisible provides function to set worksheet visible by given worksheet // SetSheetVisible provides a function to set worksheet visible by given worksheet
// name. A workbook must contain at least one visible worksheet. If the given // name. A workbook must contain at least one visible worksheet. If the given
// worksheet has been activated, this setting will be invalidated. Sheet state // worksheet has been activated, this setting will be invalidated. Sheet state
// values as defined by http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetstatevalues.aspx // values as defined by http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.sheetstatevalues.aspx
@ -510,14 +510,14 @@ func (f *File) SetSheetVisible(name string, visible bool) {
} }
} }
// parseFormatPanesSet provides function to parse the panes settings. // parseFormatPanesSet provides a function to parse the panes settings.
func parseFormatPanesSet(formatSet string) (*formatPanes, error) { func parseFormatPanesSet(formatSet string) (*formatPanes, error) {
format := formatPanes{} format := formatPanes{}
err := json.Unmarshal([]byte(formatSet), &format) err := json.Unmarshal([]byte(formatSet), &format)
return &format, err return &format, err
} }
// SetPanes provides function to create and remove freeze panes and split panes // SetPanes provides a function to create and remove freeze panes and split panes
// by given worksheet name and panes format set. // by given worksheet name and panes format set.
// //
// activePane defines the pane that is active. The possible values for this // activePane defines the pane that is active. The possible values for this
@ -631,7 +631,7 @@ func (f *File) SetPanes(sheet, panes string) {
xlsx.SheetViews.SheetView[len(xlsx.SheetViews.SheetView)-1].Selection = s xlsx.SheetViews.SheetView[len(xlsx.SheetViews.SheetView)-1].Selection = s
} }
// GetSheetVisible provides function to get worksheet visible by given worksheet // GetSheetVisible provides a function to get worksheet visible by given worksheet
// name. For example, get visible state of Sheet1: // name. For example, get visible state of Sheet1:
// //
// xlsx.GetSheetVisible("Sheet1") // xlsx.GetSheetVisible("Sheet1")
@ -649,7 +649,7 @@ func (f *File) GetSheetVisible(name string) bool {
return visible return visible
} }
// trimSheetName provides function to trim invaild characters by given worksheet // trimSheetName provides a function to trim invaild characters by given worksheet
// name. // name.
func trimSheetName(name string) string { func trimSheetName(name string) string {
r := []rune{} r := []rune{}

View File

@ -98,7 +98,7 @@ func (o *AutoPageBreaks) getSheetPrOption(pr *xlsxSheetPr) {
*o = AutoPageBreaks(pr.PageSetUpPr.AutoPageBreaks) *o = AutoPageBreaks(pr.PageSetUpPr.AutoPageBreaks)
} }
// SetSheetPrOptions provides function to sets worksheet properties. // SetSheetPrOptions provides a function to sets worksheet properties.
// //
// Available options: // Available options:
// CodeName(string) // CodeName(string)
@ -120,7 +120,7 @@ func (f *File) SetSheetPrOptions(name string, opts ...SheetPrOption) error {
return nil return nil
} }
// GetSheetPrOptions provides function to gets worksheet properties. // GetSheetPrOptions provides a function to gets worksheet properties.
// //
// Available options: // Available options:
// CodeName(string) // CodeName(string)

153
styles.go
View File

@ -10,8 +10,8 @@ import (
) )
// Excel styles can reference number formats that are built-in, all of which // Excel styles can reference number formats that are built-in, all of which
// have an id less than 164. This is a possibly incomplete list comprised of as // have an id less than 164. This is a possibly incomplete list comprised of
// many of them as I could find. // as many of them as I could find.
var builtInNumFmt = map[int]string{ var builtInNumFmt = map[int]string{
0: "general", 0: "general",
1: "0", 1: "0",
@ -829,14 +829,15 @@ var criteriaType = map[string]string{
"continue month": "continueMonth", "continue month": "continueMonth",
} }
// formatToString provides function to return original string by given built-in // formatToString provides a function to return original string by given
// number formats code and cell string. // built-in number formats code and cell string.
func formatToString(i int, v string) string { func formatToString(i int, v string) string {
return v return v
} }
// formatToInt provides function to convert original string to integer format as // formatToInt provides a function to convert original string to integer
// string type by given built-in number formats code and cell string. // format as string type by given built-in number formats code and cell
// string.
func formatToInt(i int, v string) string { func formatToInt(i int, v string) string {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
@ -845,8 +846,9 @@ func formatToInt(i int, v string) string {
return fmt.Sprintf("%d", int(f)) return fmt.Sprintf("%d", int(f))
} }
// formatToFloat provides function to convert original string to float format as // formatToFloat provides a function to convert original string to float
// string type by given built-in number formats code and cell string. // format as string type by given built-in number formats code and cell
// string.
func formatToFloat(i int, v string) string { func formatToFloat(i int, v string) string {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
@ -855,8 +857,8 @@ func formatToFloat(i int, v string) string {
return fmt.Sprintf("%.2f", f) return fmt.Sprintf("%.2f", f)
} }
// formatToA provides function to convert original string to special format as // formatToA provides a function to convert original string to special format
// string type by given built-in number formats code and cell string. // as string type by given built-in number formats code and cell string.
func formatToA(i int, v string) string { func formatToA(i int, v string) string {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
@ -870,8 +872,8 @@ func formatToA(i int, v string) string {
return fmt.Sprintf("%d", t) return fmt.Sprintf("%d", t)
} }
// formatToB provides function to convert original string to special format as // formatToB provides a function to convert original string to special format
// string type by given built-in number formats code and cell string. // as string type by given built-in number formats code and cell string.
func formatToB(i int, v string) string { func formatToB(i int, v string) string {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
@ -883,8 +885,8 @@ func formatToB(i int, v string) string {
return fmt.Sprintf("%.2f", f) return fmt.Sprintf("%.2f", f)
} }
// formatToC provides function to convert original string to special format as // formatToC provides a function to convert original string to special format
// string type by given built-in number formats code and cell string. // as string type by given built-in number formats code and cell string.
func formatToC(i int, v string) string { func formatToC(i int, v string) string {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
@ -894,8 +896,8 @@ func formatToC(i int, v string) string {
return fmt.Sprintf("%d%%", int(f)) return fmt.Sprintf("%d%%", int(f))
} }
// formatToD provides function to convert original string to special format as // formatToD provides a function to convert original string to special format
// string type by given built-in number formats code and cell string. // as string type by given built-in number formats code and cell string.
func formatToD(i int, v string) string { func formatToD(i int, v string) string {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
@ -905,8 +907,8 @@ func formatToD(i int, v string) string {
return fmt.Sprintf("%.2f%%", f) return fmt.Sprintf("%.2f%%", f)
} }
// formatToE provides function to convert original string to special format as // formatToE provides a function to convert original string to special format
// string type by given built-in number formats code and cell string. // as string type by given built-in number formats code and cell string.
func formatToE(i int, v string) string { func formatToE(i int, v string) string {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
@ -915,17 +917,17 @@ func formatToE(i int, v string) string {
return fmt.Sprintf("%.e", f) return fmt.Sprintf("%.e", f)
} }
// parseTime provides function to returns a string parsed using time.Time. // parseTime provides a function to returns a string parsed using time.Time.
// Replace Excel placeholders with Go time placeholders. For example, replace // Replace Excel placeholders with Go time placeholders. For example, replace
// yyyy with 2006. These are in a specific order, due to the fact that m is used // yyyy with 2006. These are in a specific order, due to the fact that m is
// in month, minute, and am/pm. It would be easier to fix that with regular // used in month, minute, and am/pm. It would be easier to fix that with
// expressions, but if it's possible to keep this simple it would be easier to // regular expressions, but if it's possible to keep this simple it would be
// maintain. Full-length month and days (e.g. March, Tuesday) have letters in // easier to maintain. Full-length month and days (e.g. March, Tuesday) have
// them that would be replaced by other characters below (such as the 'h' in // letters in them that would be replaced by other characters below (such as
// March, or the 'd' in Tuesday) below. First we convert them to arbitrary // the 'h' in March, or the 'd' in Tuesday) below. First we convert them to
// characters unused in Excel Date formats, and then at the end, turn them to // arbitrary characters unused in Excel Date formats, and then at the end,
// what they should actually be. // turn them to what they should actually be. Based off:
// Based off: http://www.ozgrid.com/Excel/CustomFormats.htm // http://www.ozgrid.com/Excel/CustomFormats.htm
func parseTime(i int, v string) string { func parseTime(i int, v string) string {
f, err := strconv.ParseFloat(v, 64) f, err := strconv.ParseFloat(v, 64)
if err != nil { if err != nil {
@ -983,7 +985,7 @@ func is12HourTime(format string) bool {
return strings.Contains(format, "am/pm") || strings.Contains(format, "AM/PM") || strings.Contains(format, "a/p") || strings.Contains(format, "A/P") return strings.Contains(format, "am/pm") || strings.Contains(format, "AM/PM") || strings.Contains(format, "a/p") || strings.Contains(format, "A/P")
} }
// stylesReader provides function to get the pointer to the structure after // stylesReader provides a function to get the pointer to the structure after
// deserialization of xl/styles.xml. // deserialization of xl/styles.xml.
func (f *File) stylesReader() *xlsxStyleSheet { func (f *File) stylesReader() *xlsxStyleSheet {
if f.Styles == nil { if f.Styles == nil {
@ -994,7 +996,7 @@ func (f *File) stylesReader() *xlsxStyleSheet {
return f.Styles return f.Styles
} }
// styleSheetWriter provides function to save xl/styles.xml after serialize // styleSheetWriter provides a function to save xl/styles.xml after serialize
// structure. // structure.
func (f *File) styleSheetWriter() { func (f *File) styleSheetWriter() {
if f.Styles != nil { if f.Styles != nil {
@ -1003,7 +1005,7 @@ func (f *File) styleSheetWriter() {
} }
} }
// parseFormatStyleSet provides function to parse the format settings of the // parseFormatStyleSet provides a function to parse the format settings of the
// cells and conditional formats. // cells and conditional formats.
func parseFormatStyleSet(style string) (*formatStyle, error) { func parseFormatStyleSet(style string) (*formatStyle, error) {
format := formatStyle{ format := formatStyle{
@ -1013,8 +1015,8 @@ func parseFormatStyleSet(style string) (*formatStyle, error) {
return &format, err return &format, err
} }
// NewStyle provides function to create style for cells by given style format. // NewStyle provides a function to create style for cells by given style
// Note that the color field uses RGB color code. // format. Note that the color field uses RGB color code.
// //
// The following shows the border styles sorted by excelize index number: // The following shows the border styles sorted by excelize index number:
// //
@ -1906,10 +1908,10 @@ func (f *File) NewStyle(style string) (int, error) {
return cellXfsID, nil return cellXfsID, nil
} }
// NewConditionalStyle provides function to create style for conditional format // NewConditionalStyle provides a function to create style for conditional
// by given style format. The parameters are the same as function NewStyle(). // format by given style format. The parameters are the same as function
// Note that the color field uses RGB color code and only support to set font, // NewStyle(). Note that the color field uses RGB color code and only support
// fills, alignment and borders currently. // to set font, fills, alignment and borders currently.
func (f *File) NewConditionalStyle(style string) (int, error) { func (f *File) NewConditionalStyle(style string) (int, error) {
s := f.stylesReader() s := f.stylesReader()
fs, err := parseFormatStyleSet(style) fs, err := parseFormatStyleSet(style)
@ -1935,7 +1937,8 @@ func (f *File) NewConditionalStyle(style string) (int, error) {
return s.Dxfs.Count - 1, nil return s.Dxfs.Count - 1, nil
} }
// setFont provides function to add font style by given cell format settings. // setFont provides a function to add font style by given cell format
// settings.
func setFont(formatStyle *formatStyle) *font { func setFont(formatStyle *formatStyle) *font {
fontUnderlineType := map[string]string{"single": "single", "double": "double"} fontUnderlineType := map[string]string{"single": "single", "double": "double"}
if formatStyle.Font.Size < 1 { if formatStyle.Font.Size < 1 {
@ -1963,8 +1966,8 @@ func setFont(formatStyle *formatStyle) *font {
return &f return &f
} }
// setNumFmt provides function to check if number format code in the range of // setNumFmt provides a function to check if number format code in the range
// built-in values. // of built-in values.
func setNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { func setNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
dp := "0." dp := "0."
numFmtID := 164 // Default custom number format code from 164. numFmtID := 164 // Default custom number format code from 164.
@ -2011,7 +2014,7 @@ func setNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
return formatStyle.NumFmt return formatStyle.NumFmt
} }
// setCustomNumFmt provides function to set custom number format code. // setCustomNumFmt provides a function to set custom number format code.
func setCustomNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { func setCustomNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
nf := xlsxNumFmt{FormatCode: *formatStyle.CustomNumFmt} nf := xlsxNumFmt{FormatCode: *formatStyle.CustomNumFmt}
if style.NumFmts != nil { if style.NumFmts != nil {
@ -2029,7 +2032,7 @@ func setCustomNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
return nf.NumFmtID return nf.NumFmtID
} }
// setLangNumFmt provides function to set number format code with language. // setLangNumFmt provides a function to set number format code with language.
func setLangNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { func setLangNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
numFmts, ok := langNumFmt[formatStyle.Lang] numFmts, ok := langNumFmt[formatStyle.Lang]
if !ok { if !ok {
@ -2056,8 +2059,8 @@ func setLangNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
return nf.NumFmtID return nf.NumFmtID
} }
// setFills provides function to add fill elements in the styles.xml by given // setFills provides a function to add fill elements in the styles.xml by
// cell format settings. // given cell format settings.
func setFills(formatStyle *formatStyle, fg bool) *xlsxFill { func setFills(formatStyle *formatStyle, fg bool) *xlsxFill {
var patterns = []string{ var patterns = []string{
"none", "none",
@ -2137,9 +2140,10 @@ func setFills(formatStyle *formatStyle, fg bool) *xlsxFill {
return &fill return &fill
} }
// setAlignment provides function to formatting information pertaining to text // setAlignment provides a function to formatting information pertaining to
// alignment in cells. There are a variety of choices for how text is aligned // text alignment in cells. There are a variety of choices for how text is
// both horizontally and vertically, as well as indentation settings, and so on. // aligned both horizontally and vertically, as well as indentation settings,
// and so on.
func setAlignment(formatStyle *formatStyle) *xlsxAlignment { func setAlignment(formatStyle *formatStyle) *xlsxAlignment {
var alignment xlsxAlignment var alignment xlsxAlignment
if formatStyle.Alignment != nil { if formatStyle.Alignment != nil {
@ -2156,7 +2160,7 @@ func setAlignment(formatStyle *formatStyle) *xlsxAlignment {
return &alignment return &alignment
} }
// setProtection provides function to set protection properties associated // setProtection provides a function to set protection properties associated
// with the cell. // with the cell.
func setProtection(formatStyle *formatStyle) *xlsxProtection { func setProtection(formatStyle *formatStyle) *xlsxProtection {
var protection xlsxProtection var protection xlsxProtection
@ -2167,7 +2171,7 @@ func setProtection(formatStyle *formatStyle) *xlsxProtection {
return &protection return &protection
} }
// setBorders provides function to add border elements in the styles.xml by // setBorders provides a function to add border elements in the styles.xml by
// given borders format settings. // given borders format settings.
func setBorders(formatStyle *formatStyle) *xlsxBorder { func setBorders(formatStyle *formatStyle) *xlsxBorder {
var styles = []string{ var styles = []string{
@ -2219,7 +2223,7 @@ func setBorders(formatStyle *formatStyle) *xlsxBorder {
return &border return &border
} }
// setCellXfs provides function to set describes all of the formatting for a // setCellXfs provides a function to set describes all of the formatting for a
// cell. // cell.
func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment, applyProtection bool, alignment *xlsxAlignment, protection *xlsxProtection) int { func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment, applyProtection bool, alignment *xlsxAlignment, protection *xlsxProtection) int {
var xf xlsxXf var xf xlsxXf
@ -2246,9 +2250,10 @@ func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, a
return style.CellXfs.Count - 1 return style.CellXfs.Count - 1
} }
// SetCellStyle provides function to add style attribute for cells by given // SetCellStyle provides a function to add style attribute for cells by given
// worksheet name, coordinate area and style ID. Note that diagonalDown and // worksheet name, coordinate area and style ID. Note that diagonalDown and
// diagonalUp type border should be use same color in the same coordinate area. // diagonalUp type border should be use same color in the same coordinate
// area.
// //
// For example create a borders of cell H9 on Sheet1: // For example create a borders of cell H9 on Sheet1:
// //
@ -2352,9 +2357,10 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
} }
} }
// SetConditionalFormat provides function to create conditional formatting rule // SetConditionalFormat provides a function to create conditional formatting
// for cell value. Conditional formatting is a feature of Excel which allows you // rule for cell value. Conditional formatting is a feature of Excel which
// to apply a format to a cell or a range of cells based on certain criteria. // allows you to apply a format to a cell or a range of cells based on certain
// criteria.
// //
// The type option is a required parameter and it has no default value. // The type option is a required parameter and it has no default value.
// Allowable type values and their associated parameters are: // Allowable type values and their associated parameters are:
@ -2606,9 +2612,9 @@ func (f *File) SetConditionalFormat(sheet, area, formatSet string) error {
return err return err
} }
// drawCondFmtCellIs provides function to create conditional formatting rule for // drawCondFmtCellIs provides a function to create conditional formatting rule
// cell value (include between, not between, equal, not equal, greater than and // for cell value (include between, not between, equal, not equal, greater
// less than) by given priority, criteria type and format settings. // than and less than) by given priority, criteria type and format settings.
func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule { func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule {
c := &xlsxCfRule{ c := &xlsxCfRule{
Priority: p + 1, Priority: p + 1,
@ -2629,8 +2635,8 @@ func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule
return c return c
} }
// drawCondFmtTop10 provides function to create conditional formatting rule for // drawCondFmtTop10 provides a function to create conditional formatting rule
// top N (default is top 10) by given priority, criteria type and format // for top N (default is top 10) by given priority, criteria type and format
// settings. // settings.
func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule { func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule {
c := &xlsxCfRule{ c := &xlsxCfRule{
@ -2647,9 +2653,9 @@ func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule {
return c return c
} }
// drawCondFmtAboveAverage provides function to create conditional formatting // drawCondFmtAboveAverage provides a function to create conditional
// rule for above average and below average by given priority, criteria type and // formatting rule for above average and below average by given priority,
// format settings. // criteria type and format settings.
func drawCondFmtAboveAverage(p int, ct string, format *formatConditional) *xlsxCfRule { func drawCondFmtAboveAverage(p int, ct string, format *formatConditional) *xlsxCfRule {
return &xlsxCfRule{ return &xlsxCfRule{
Priority: p + 1, Priority: p + 1,
@ -2659,7 +2665,7 @@ func drawCondFmtAboveAverage(p int, ct string, format *formatConditional) *xlsxC
} }
} }
// drawCondFmtDuplicateUniqueValues provides function to create conditional // drawCondFmtDuplicateUniqueValues provides a function to create conditional
// formatting rule for duplicate and unique values by given priority, criteria // formatting rule for duplicate and unique values by given priority, criteria
// type and format settings. // type and format settings.
func drawCondFmtDuplicateUniqueValues(p int, ct string, format *formatConditional) *xlsxCfRule { func drawCondFmtDuplicateUniqueValues(p int, ct string, format *formatConditional) *xlsxCfRule {
@ -2670,9 +2676,9 @@ func drawCondFmtDuplicateUniqueValues(p int, ct string, format *formatConditiona
} }
} }
// drawCondFmtColorScale provides function to create conditional formatting rule // drawCondFmtColorScale provides a function to create conditional formatting
// for color scale (include 2 color scale and 3 color scale) by given priority, // rule for color scale (include 2 color scale and 3 color scale) by given
// criteria type and format settings. // priority, criteria type and format settings.
func drawCondFmtColorScale(p int, ct string, format *formatConditional) *xlsxCfRule { func drawCondFmtColorScale(p int, ct string, format *formatConditional) *xlsxCfRule {
minValue := format.MinValue minValue := format.MinValue
if minValue == "" { if minValue == "" {
@ -2708,8 +2714,8 @@ func drawCondFmtColorScale(p int, ct string, format *formatConditional) *xlsxCfR
return c return c
} }
// drawCondFmtDataBar provides function to create conditional formatting rule // drawCondFmtDataBar provides a function to create conditional formatting
// for data bar by given priority, criteria type and format settings. // rule for data bar by given priority, criteria type and format settings.
func drawCondFmtDataBar(p int, ct string, format *formatConditional) *xlsxCfRule { func drawCondFmtDataBar(p int, ct string, format *formatConditional) *xlsxCfRule {
return &xlsxCfRule{ return &xlsxCfRule{
Priority: p + 1, Priority: p + 1,
@ -2721,8 +2727,8 @@ func drawCondFmtDataBar(p int, ct string, format *formatConditional) *xlsxCfRule
} }
} }
// drawConfFmtExp provides function to create conditional formatting rule for // drawConfFmtExp provides a function to create conditional formatting rule
// expression by given priority, criteria type and format settings. // for expression by given priority, criteria type and format settings.
func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule { func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule {
return &xlsxCfRule{ return &xlsxCfRule{
Priority: p + 1, Priority: p + 1,
@ -2732,12 +2738,13 @@ func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule {
} }
} }
// getPaletteColor provides function to convert the RBG color by given string. // getPaletteColor provides a function to convert the RBG color by given
// string.
func getPaletteColor(color string) string { func getPaletteColor(color string) string {
return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1) return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1)
} }
// themeReader provides function to get the pointer to the xl/theme/theme1.xml // themeReader provides a function to get the pointer to the xl/theme/theme1.xml
// structure after deserialization. // structure after deserialization.
func (f *File) themeReader() *xlsxTheme { func (f *File) themeReader() *xlsxTheme {
var theme xlsxTheme var theme xlsxTheme

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
) )
// parseFormatTableSet provides function to parse the format settings of the // parseFormatTableSet provides a function to parse the format settings of the
// table with default value. // table with default value.
func parseFormatTableSet(formatSet string) (*formatTable, error) { func parseFormatTableSet(formatSet string) (*formatTable, error) {
format := formatTable{ format := formatTable{
@ -75,8 +75,8 @@ func (f *File) AddTable(sheet, hcell, vcell, format string) error {
return err return err
} }
// countTables provides function to get table files count storage in the folder // countTables provides a function to get table files count storage in the
// xl/tables. // folder xl/tables.
func (f *File) countTables() int { func (f *File) countTables() int {
count := 0 count := 0
for k := range f.XLSX { for k := range f.XLSX {
@ -87,7 +87,7 @@ func (f *File) countTables() int {
return count return count
} }
// addSheetTable provides function to add tablePart element to // addSheetTable provides a function to add tablePart element to
// xl/worksheets/sheet%d.xml by given worksheet name and relationship index. // xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
func (f *File) addSheetTable(sheet string, rID int) { func (f *File) addSheetTable(sheet string, rID int) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -101,8 +101,8 @@ func (f *File) addSheetTable(sheet string, rID int) {
xlsx.TableParts.TableParts = append(xlsx.TableParts.TableParts, table) xlsx.TableParts.TableParts = append(xlsx.TableParts.TableParts, table)
} }
// addTable provides function to add table by given worksheet name, coordinate // addTable provides a function to add table by given worksheet name,
// area and format set. // coordinate area and format set.
func (f *File) addTable(sheet, tableXML string, hxAxis, hyAxis, vxAxis, vyAxis, i int, formatSet *formatTable) { func (f *File) addTable(sheet, tableXML string, hxAxis, hyAxis, vxAxis, vyAxis, i int, formatSet *formatTable) {
// Correct the minimum number of rows, the table at least two lines. // Correct the minimum number of rows, the table at least two lines.
if hyAxis == vyAxis { if hyAxis == vyAxis {
@ -157,7 +157,7 @@ func (f *File) addTable(sheet, tableXML string, hxAxis, hyAxis, vxAxis, vyAxis,
f.saveFileList(tableXML, table) f.saveFileList(tableXML, table)
} }
// parseAutoFilterSet provides function to parse the settings of the auto // parseAutoFilterSet provides a function to parse the settings of the auto
// filter. // filter.
func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) { func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
format := formatAutoFilter{} format := formatAutoFilter{}
@ -264,7 +264,7 @@ func (f *File) AutoFilter(sheet, hcell, vcell, format string) error {
return f.autoFilter(sheet, ref, refRange, hxAxis, formatSet) return f.autoFilter(sheet, ref, refRange, hxAxis, formatSet)
} }
// autoFilter provides function to extract the tokens from the filter // autoFilter provides a function to extract the tokens from the filter
// expression. The tokens are mainly non-whitespace groups. // expression. The tokens are mainly non-whitespace groups.
func (f *File) autoFilter(sheet, ref string, refRange, hxAxis int, formatSet *formatAutoFilter) error { func (f *File) autoFilter(sheet, ref string, refRange, hxAxis int, formatSet *formatAutoFilter) error {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
@ -301,8 +301,8 @@ func (f *File) autoFilter(sheet, ref string, refRange, hxAxis int, formatSet *fo
return nil return nil
} }
// writeAutoFilter provides function to check for single or double custom filters // writeAutoFilter provides a function to check for single or double custom
// as default filters and handle them accordingly. // filters as default filters and handle them accordingly.
func (f *File) writeAutoFilter(filter *xlsxAutoFilter, exp []int, tokens []string) { func (f *File) writeAutoFilter(filter *xlsxAutoFilter, exp []int, tokens []string) {
if len(exp) == 1 && exp[0] == 2 { if len(exp) == 1 && exp[0] == 2 {
// Single equality. // Single equality.
@ -329,7 +329,7 @@ func (f *File) writeAutoFilter(filter *xlsxAutoFilter, exp []int, tokens []strin
} }
} }
// writeCustomFilter provides function to write the <customFilter> element. // writeCustomFilter provides a function to write the <customFilter> element.
func (f *File) writeCustomFilter(filter *xlsxAutoFilter, operator int, val string) { func (f *File) writeCustomFilter(filter *xlsxAutoFilter, operator int, val string) {
operators := map[int]string{ operators := map[int]string{
1: "lessThan", 1: "lessThan",
@ -353,8 +353,9 @@ func (f *File) writeCustomFilter(filter *xlsxAutoFilter, operator int, val strin
} }
} }
// parseFilterExpression provides function to converts the tokens of a possibly // parseFilterExpression provides a function to converts the tokens of a
// conditional expression into 1 or 2 sub expressions for further parsing. // possibly conditional expression into 1 or 2 sub expressions for further
// parsing.
// //
// Examples: // Examples:
// //
@ -394,7 +395,7 @@ func (f *File) parseFilterExpression(expression string, tokens []string) ([]int,
return expressions, t, nil return expressions, t, nil
} }
// parseFilterTokens provides function to parse the 3 tokens of a filter // parseFilterTokens provides a function to parse the 3 tokens of a filter
// expression and return the operator and token. // expression and return the operator and token.
func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, string, error) { func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, string, error) {
operators := map[string]int{ operators := map[string]int{