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"
)
// mergeCellsParser provides function to check merged cells in worksheet by
// mergeCellsParser provides a function to check merged cells in worksheet by
// given axis.
func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
axis = strings.ToUpper(axis)
@ -34,8 +34,8 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
return axis
}
// SetCellValue provides function to set value of a cell. The following shows
// the supported data types:
// SetCellValue provides a function to set value of a cell. The following
// shows the supported data types:
//
// int
// 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{}) {
switch value.(type) {
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.
func (f *File) SetCellBool(sheet, axis string, value bool) {
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
// worksheet name and axis in XLSX file. If it is possible to apply a format to
// the cell value, it will do so, if not then an error will be returned, along
// with the raw value of the cell.
// 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 the cell value, it will do so, if not then an error will be returned,
// along with the raw value of the cell.
func (f *File) GetCellValue(sheet, axis string) string {
xlsx := f.workSheetReader(sheet)
axis = f.mergeCellsParser(xlsx, axis)
@ -174,9 +174,9 @@ func (f *File) GetCellValue(sheet, axis string) string {
return ""
}
// formattedValue provides function to returns a value after formatted. If it is
// possible to apply a format to the cell value, it will do so, if not then an
// error will be returned, along with the raw value of the cell.
// formattedValue provides a function to returns a value after formatted. If
// it is possible to apply a format to the cell value, it will do so, if not
// then an error will be returned, along with the raw value of the cell.
func (f *File) formattedValue(s int, v string) string {
if s == 0 {
return v
@ -189,7 +189,7 @@ func (f *File) formattedValue(s int, v string) string {
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.
func (f *File) GetCellStyle(sheet, axis string) int {
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)
}
// GetCellFormula provides function to get formula from cell by given worksheet
// name and axis in XLSX file.
// GetCellFormula provides a function to get formula from cell by given
// worksheet name and axis in XLSX file.
func (f *File) GetCellFormula(sheet, axis string) string {
xlsx := f.workSheetReader(sheet)
axis = f.mergeCellsParser(xlsx, axis)
@ -276,7 +276,7 @@ func getSharedForumula(xlsx *xlsxWorksheet, si string) string {
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.
func (f *File) SetCellFormula(sheet, axis, formula string) {
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
// name and link URL address. LinkType defines two types of hyperlink "External"
// for web site or "Location" for moving to one of cell in this workbook. The
// below is example for external link.
// SetCellHyperLink provides a function to set cell hyperlink by given
// worksheet name and link URL address. LinkType defines two types of
// hyperlink "External" for web site or "Location" for moving to one of cell
// in this workbook. The below is example for external link.
//
// xlsx.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
// // 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)
}
// GetCellHyperLink provides function to get cell hyperlink by given worksheet
// name and axis. Boolean type value link will be ture if the cell has a
// hyperlink and the target is the address of the hyperlink. Otherwise, the
// value of link will be false and the value of the target will be a blank
// GetCellHyperLink provides a function to get cell hyperlink by given
// worksheet name and axis. Boolean type value link will be ture if the cell
// has a hyperlink and the target is the address of the hyperlink. Otherwise,
// 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:
//
// link, target := xlsx.GetCellHyperLink("Sheet1", "H6")
@ -369,8 +369,8 @@ func (f *File) GetCellHyperLink(sheet, axis string) (bool, string) {
return link, target
}
// MergeCell provides function to merge cells by given coordinate area and sheet
// name. For example create a merged cell of D3:E9 on Sheet1:
// MergeCell provides a function to merge cells by given coordinate area and
// sheet name. For example create a merged cell of D3:E9 on Sheet1:
//
// 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.
func (f *File) SetCellInt(sheet, axis string, value int) {
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)
}
// 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.
func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int {
if xlsx.Cols != nil && style == 0 {
@ -466,8 +466,8 @@ func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int {
return style
}
// SetCellStr provides function to set string type value of a cell. Total number
// of characters that a cell can contain 32767 characters.
// SetCellStr provides a function to set string type value of a cell. Total
// number of characters that a cell can contain 32767 characters.
func (f *File) SetCellStr(sheet, axis, value string) {
xlsx := f.workSheetReader(sheet)
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
}
// 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.
func (f *File) SetCellDefault(sheet, axis, value string) {
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.
func checkCellInArea(cell, area string) bool {
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.
func parseFormatChartSet(formatSet string) (*formatChart, error) {
format := formatChart{
@ -379,7 +379,7 @@ func (f *File) AddChart(sheet, cell, format string) error {
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.
func (f *File) countCharts() int {
count := 0
@ -391,7 +391,7 @@ func (f *File) countCharts() int {
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.
func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) {
sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
@ -408,8 +408,8 @@ func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawing
return drawingID, drawingXML
}
// addChart provides function to create chart as xl/charts/chart%d.xml by given
// format sets.
// addChart provides a function to create chart as xl/charts/chart%d.xml by
// given format sets.
func (f *File) addChart(formatSet *formatChart) {
count := f.countCharts()
xlsxChartSpace := xlsxChartSpace{
@ -564,7 +564,7 @@ func (f *File) addChart(formatSet *formatChart) {
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.
func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea {
c := cCharts{
@ -661,7 +661,7 @@ func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea {
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.
func (f *File) drawDoughnutChart(formatSet *formatChart) *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
// by given format sets.
// drawLineChart provides a function to draw the c:plotArea element for line
// chart by given format sets.
func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{
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
// by given format sets.
// drawPieChart provides a function to draw the c:plotArea element for pie
// chart by given format sets.
func (f *File) drawPieChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{
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
// chart by given format sets.
// drawPie3DChart provides a function to draw the c:plotArea element for 3D
// pie chart by given format sets.
func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{
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.
func (f *File) drawRadarChart(formatSet *formatChart) *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
// chart by given format sets.
// drawScatterChart provides a function to draw the c:plotArea element for
// scatter chart by given format sets.
func (f *File) drawScatterChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{
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
// sets.
// drawChartSeries provides a function to draw the c:ser element by given
// format sets.
func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer {
ser := []cSer{}
for k := range formatSet.Series {
@ -799,7 +799,7 @@ func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer {
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.
func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr {
spPrScatter := &cSpPr{
@ -821,8 +821,8 @@ func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr {
return chartSeriesSpPr[formatSet.Type]
}
// drawChartSeriesDPt provides function to draw the c:dPt element by given data
// index and format sets.
// drawChartSeriesDPt provides a function to draw the c:dPt element by given
// data index and format sets.
func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt {
dpt := []*cDPt{{
IDx: &attrValInt{Val: i},
@ -850,8 +850,8 @@ func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt {
return chartSeriesDPt[formatSet.Type]
}
// drawChartSeriesCat provides function to draw the c:cat element by given chart
// series and format sets.
// drawChartSeriesCat provides a function to draw the c:cat element by given
// chart series and format sets.
func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *cCat {
cat := &cCat{
StrRef: &cStrRef{
@ -862,8 +862,8 @@ func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *
return chartSeriesCat[formatSet.Type]
}
// drawChartSeriesVal provides function to draw the c:val element by given chart
// series and format sets.
// drawChartSeriesVal provides a function to draw the c:val element by given
// chart series and format sets.
func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *cVal {
val := &cVal{
NumRef: &cNumRef{
@ -874,8 +874,8 @@ func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *
return chartSeriesVal[formatSet.Type]
}
// drawChartSeriesMarker provides function to draw the c:marker element by given
// data index and format sets.
// drawChartSeriesMarker provides a function to draw the c:marker element by
// given data index and format sets.
func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker {
marker := &cMarker{
Symbol: &attrValString{Val: "circle"},
@ -900,7 +900,7 @@ func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker {
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.
func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart) *cCat {
cat := &cCat{
@ -912,7 +912,7 @@ func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart)
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.
func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart) *cVal {
val := &cVal{
@ -924,8 +924,8 @@ func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart)
return chartSeriesYVal[formatSet.Type]
}
// drawChartDLbls provides function to draw the c:dLbls element by given format
// sets.
// drawChartDLbls provides a function to draw the c:dLbls element by given
// format sets.
func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls {
return &cDLbls{
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
// format sets.
// drawChartSeriesDLbls provides a function to draw the c:dLbls element by
// given format sets.
func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls {
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}
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 {
min := &attrValFloat{Val: formatSet.XAxis.Minimum}
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 {
min := &attrValFloat{Val: formatSet.YAxis.Minimum}
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 {
return &cSpPr{
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 {
return &cTxPr{
BodyPr: aBodyPr{
@ -1079,8 +1079,8 @@ func (f *File) drawPlotAreaTxPr() *cTxPr {
}
}
// drawingParser provides function to parse drawingXML. In order to solve the
// problem that the label structure is changed after serialization and
// drawingParser provides a function to parse drawingXML. In order to solve
// the problem that the label structure is changed after serialization and
// deserialization, two different structures: decodeWsDr and encodeWsDr are
// defined.
func (f *File) drawingParser(drawingXML string, content *xlsxWsDr) int {
@ -1107,8 +1107,8 @@ func (f *File) drawingParser(drawingXML string, content *xlsxWsDr) int {
return cNvPrID
}
// addDrawingChart provides function to add chart graphic frame by given sheet,
// drawingXML, cell, width, height, relationship index and format sets.
// addDrawingChart provides a function to add chart graphic frame by given
// sheet, drawingXML, cell, width, height, relationship index and format sets.
func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rID int, formatSet *formatPicture) {
cell = strings.ToUpper(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)
}
// SetColWidth provides function to set the width of a single column or multiple
// columns. For example:
// SetColWidth provides a function to set the width of a single column or
// multiple columns. For example:
//
// xlsx := excelize.NewFile()
// 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
}
// getColWidth provides function to get column width in pixels by given sheet
// name and column index.
// getColWidth provides a function to get column width in pixels by given
// sheet name and column index.
func (f *File) getColWidth(sheet string, col int) int {
xlsx := f.workSheetReader(sheet)
if xlsx.Cols != nil {
@ -278,8 +278,8 @@ func (f *File) getColWidth(sheet string, col int) int {
return int(defaultColWidthPixels)
}
// GetColWidth provides function to get column width by given worksheet name and
// column index.
// GetColWidth provides a function to get column width by given worksheet name
// and column index.
func (f *File) GetColWidth(sheet, column string) float64 {
col := TitleToNumber(strings.ToUpper(column)) + 1
xlsx := f.workSheetReader(sheet)
@ -298,8 +298,8 @@ func (f *File) GetColWidth(sheet, column string) float64 {
return defaultColWidthPixels
}
// InsertCol provides function to insert a new column before given column index.
// For example, create a new column before column C in Sheet1:
// InsertCol provides a function to insert a new column before given column
// index. For example, create a new column before column C in Sheet1:
//
// xlsx.InsertCol("Sheet1", "C")
//
@ -308,8 +308,8 @@ func (f *File) InsertCol(sheet, column string) {
f.adjustHelper(sheet, col, -1, 1)
}
// RemoveCol provides function to remove single column by given worksheet name
// and column index. For example, remove column C in Sheet1:
// RemoveCol provides a function to remove single column by given worksheet
// name and column index. For example, remove column C in Sheet1:
//
// 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
// user's units to pixels. Excel rounds the column width to the nearest pixel.
// If the width hasn't been set by the user we use the default value. If the
// column is hidden it has a value of zero.
// convertColWidthToPixels provieds function to convert the width of a cell
// from user's units to pixels. Excel rounds the column width to the nearest
// pixel. If the width hasn't been set by the user we use the default value.
// If the column is hidden it has a value of zero.
func convertColWidthToPixels(width float64) float64 {
var padding float64 = 5
var pixels float64

View File

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

26
date.go
View File

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

View File

@ -71,7 +71,7 @@ func OpenReader(r io.Reader) (*File, error) {
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
// number format code.
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
// deserialization by given worksheet name.
// workSheetReader provides a function to get the pointer to the structure
// after deserialization by given worksheet name.
func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
name, ok := f.sheetMap[trimSheetName(sheet)]
if !ok {
@ -105,7 +105,7 @@ func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
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.
func checkSheet(xlsx *xlsxWorksheet) {
row := len(xlsx.SheetData.Row)
@ -133,7 +133,7 @@ func checkSheet(xlsx *xlsxWorksheet) {
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
// Office Excel 2007.
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
// columns.
//
@ -204,7 +204,7 @@ func (f *File) adjustHelper(sheet string, column, row, offset int) {
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.
func (f *File) adjustColDimensions(xlsx *xlsxWorksheet, column, offset int) {
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
// or deleting rows or columns.
// adjustRowDimensions provides a function to update row dimensions when
// inserting or deleting rows or columns.
func (f *File) adjustRowDimensions(xlsx *xlsxWorksheet, rowIndex, offset int) {
if rowIndex == -1 {
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.
func (f *File) adjustHyperlinks(sheet string, column, rowIndex, offset int) {
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
// deleting rows or columns.
// adjustMergeCellsHelper provides a function to update merged cells when
// inserting or deleting rows or columns.
func (f *File) adjustMergeCellsHelper(xlsx *xlsxWorksheet, column, rowIndex, offset int) {
if xlsx.MergeCells != nil {
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
// deleting rows or columns.
// adjustMergeCells provides a function to update merged cells when inserting
// or deleting rows or columns.
func (f *File) adjustMergeCells(xlsx *xlsxWorksheet, column, rowIndex, offset int) {
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
// or deleting rows or columns.
// adjustAutoFilter provides a function to update the auto filter when
// inserting or deleting rows or columns.
func (f *File) adjustAutoFilter(xlsx *xlsxWorksheet, column, rowIndex, offset int) {
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.
func (f *File) adjustAutoFilterHelper(xlsx *xlsxWorksheet, column, rowIndex, offset int) {
if xlsx.AutoFilter != nil {

10
file.go
View File

@ -8,7 +8,7 @@ import (
"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:
//
// xlsx := NewFile()
@ -40,7 +40,7 @@ func NewFile() *File {
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 {
if f.Path == "" {
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)
}
// SaveAs provides function to create or update to an xlsx file at the provided
// path.
// SaveAs provides a function to create or update to an xlsx file at the
// provided path.
func (f *File) SaveAs(name string) error {
file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
if err != nil {
@ -59,7 +59,7 @@ func (f *File) SaveAs(name string) error {
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 {
_, err := f.WriteTo(w)
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
}
// 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 {
if content, ok := f.XLSX[name]; ok {
return content
@ -33,8 +33,8 @@ func (f *File) readXML(name string) []byte {
return []byte{}
}
// saveFileList provides function to update given file content in file list of
// XLSX.
// saveFileList provides a function to update given file content in file list
// of XLSX.
func (f *File) saveFileList(name string, content []byte) {
newContent := make([]byte, 0, len(XMLHeader)+len(content))
newContent = append(newContent, []byte(XMLHeader)...)
@ -54,7 +54,7 @@ func readFile(file *zip.File) []byte {
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:
//
// excelize.ToAlphaString(36)
@ -72,9 +72,9 @@ func ToAlphaString(value int) string {
return ans
}
// TitleToNumber provides function to convert Excel sheet column title to int
// (this function doesn't do value check currently). For example convert AK
// and ak to column title 36:
// TitleToNumber provides a function to convert Excel sheet column title to
// int (this function doesn't do value check currently). For example convert
// AK and ak to column title 36:
//
// excelize.TitleToNumber("AK")
// excelize.TitleToNumber("ak")
@ -125,8 +125,8 @@ func defaultTrue(b *bool) bool {
return *b
}
// axisLowerOrEqualThan returns true if axis1 <= axis2
// axis1/axis2 can be either a column or a row axis, e.g. "A", "AAE", "42", "1", etc.
// axisLowerOrEqualThan returns true if axis1 <= axis2 axis1/axis2 can be
// either a column or a row axis, e.g. "A", "AAE", "42", "1", etc.
//
// 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:
//

View File

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

39
rows.go
View File

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

View File

@ -7,7 +7,7 @@ import (
"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.
func parseFormatShapeSet(formatSet string) (*formatShape, error) {
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
// 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
// Sheet1:
// print settings) and properties set. For example, add text box (rect shape)
// 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}`)
//
@ -272,7 +272,7 @@ func (f *File) AddShape(sheet, cell, format string) error {
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.
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}
@ -397,7 +397,7 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *format
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.
func setShapeRef(color string, i int) *aRef {
if color == "" {

View File

@ -14,7 +14,7 @@ import (
"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
// create a new file.
func (f *File) NewSheet(name string) int {
@ -36,7 +36,7 @@ func (f *File) NewSheet(name string) int {
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.
func (f *File) contentTypesReader() *xlsxTypes {
if f.ContentTypes == nil {
@ -47,7 +47,7 @@ func (f *File) contentTypesReader() *xlsxTypes {
return f.ContentTypes
}
// contentTypesWriter provides function to save [Content_Types].xml after
// contentTypesWriter provides a function to save [Content_Types].xml after
// serialize structure.
func (f *File) contentTypesWriter() {
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.
func (f *File) workbookReader() *xlsxWorkbook {
if f.WorkBook == nil {
@ -67,7 +67,7 @@ func (f *File) workbookReader() *xlsxWorkbook {
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.
func (f *File) workbookWriter() {
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.
func (f *File) worksheetWriter() {
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 {
col := make([]xlsxC, len(column))
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.
func (f *File) workbookRelsReader() *xlsxWorkbookRels {
if f.WorkBookRels == nil {
@ -158,7 +158,7 @@ func (f *File) workbookRelsReader() *xlsxWorkbookRels {
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.
func (f *File) workbookRelsWriter() {
if f.WorkBookRels != nil {
@ -211,7 +211,7 @@ func replaceRelationshipsNameSpaceBytes(workbookMarshal []byte) []byte {
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
// function GetSheetMap, and it should be greater than 0 and less than total
// 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.
func (f *File) GetActiveSheetIndex() int {
buffer := bytes.Buffer{}
@ -269,7 +269,7 @@ func (f *File) GetActiveSheetIndex() int {
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
// 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
@ -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
// string.
func (f *File) GetSheetName(index int) string {
@ -306,7 +306,7 @@ func (f *File) GetSheetName(index int) string {
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
// 0.
func (f *File) GetSheetIndex(name string) int {
@ -325,7 +325,7 @@ func (f *File) GetSheetIndex(name string) int {
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:
//
// xlsx, err := excelize.OpenFile("./Book1.xlsx")
@ -351,7 +351,7 @@ func (f *File) GetSheetMap() map[int]string {
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.
func (f *File) getSheetMap() map[string]string {
maps := make(map[string]string)
@ -361,7 +361,7 @@ func (f *File) getSheetMap() map[string]string {
return maps
}
// SetSheetBackground provides function to set background picture by given
// SetSheetBackground provides a function to set background picture by given
// worksheet name.
func (f *File) SetSheetBackground(sheet, picture string) error {
var err error
@ -381,7 +381,7 @@ func (f *File) SetSheetBackground(sheet, picture string) error {
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
// 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.
@ -405,7 +405,7 @@ func (f *File) DeleteSheet(name string) {
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
// xl/_rels/workbook.xml.rels.
func (f *File) deleteSheetFromWorkbookRels(rID string) string {
@ -419,7 +419,7 @@ func (f *File) deleteSheetFromWorkbookRels(rID string) string {
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.
func (f *File) deleteSheetFromContentTypes(target string) {
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
// workbooks that contain tables, charts or pictures. For Example:
//
@ -447,7 +447,7 @@ func (f *File) CopySheet(from, to int) error {
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.
func (f *File) copySheet(from, to int) {
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
// 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
@ -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) {
format := formatPanes{}
err := json.Unmarshal([]byte(formatSet), &format)
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.
//
// 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
}
// 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:
//
// xlsx.GetSheetVisible("Sheet1")
@ -649,7 +649,7 @@ func (f *File) GetSheetVisible(name string) bool {
return visible
}
// trimSheetName provides function to trim invaild characters by given worksheet
// trimSheetName provides a function to trim invaild characters by given worksheet
// name.
func trimSheetName(name string) string {
r := []rune{}

View File

@ -98,7 +98,7 @@ func (o *AutoPageBreaks) getSheetPrOption(pr *xlsxSheetPr) {
*o = AutoPageBreaks(pr.PageSetUpPr.AutoPageBreaks)
}
// SetSheetPrOptions provides function to sets worksheet properties.
// SetSheetPrOptions provides a function to sets worksheet properties.
//
// Available options:
// CodeName(string)
@ -120,7 +120,7 @@ func (f *File) SetSheetPrOptions(name string, opts ...SheetPrOption) error {
return nil
}
// GetSheetPrOptions provides function to gets worksheet properties.
// GetSheetPrOptions provides a function to gets worksheet properties.
//
// Available options:
// 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
// have an id less than 164. This is a possibly incomplete list comprised of as
// many of them as I could find.
// have an id less than 164. This is a possibly incomplete list comprised of
// as many of them as I could find.
var builtInNumFmt = map[int]string{
0: "general",
1: "0",
@ -829,14 +829,15 @@ var criteriaType = map[string]string{
"continue month": "continueMonth",
}
// formatToString provides function to return original string by given built-in
// number formats code and cell string.
// formatToString provides a function to return original string by given
// built-in number formats code and cell string.
func formatToString(i int, v string) string {
return v
}
// formatToInt provides function to convert original string to integer format as
// string type by given built-in number formats code and cell string.
// formatToInt provides a function to convert original string to integer
// format as string type by given built-in number formats code and cell
// string.
func formatToInt(i int, v string) string {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -845,8 +846,9 @@ func formatToInt(i int, v string) string {
return fmt.Sprintf("%d", int(f))
}
// formatToFloat provides function to convert original string to float format as
// string type by given built-in number formats code and cell string.
// formatToFloat provides a function to convert original string to float
// format as string type by given built-in number formats code and cell
// string.
func formatToFloat(i int, v string) string {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -855,8 +857,8 @@ func formatToFloat(i int, v string) string {
return fmt.Sprintf("%.2f", f)
}
// formatToA provides function to convert original string to special format as
// string type by given built-in number formats code and cell string.
// formatToA provides a function to convert original string to special format
// as string type by given built-in number formats code and cell string.
func formatToA(i int, v string) string {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -870,8 +872,8 @@ func formatToA(i int, v string) string {
return fmt.Sprintf("%d", t)
}
// formatToB provides function to convert original string to special format as
// string type by given built-in number formats code and cell string.
// formatToB provides a function to convert original string to special format
// as string type by given built-in number formats code and cell string.
func formatToB(i int, v string) string {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -883,8 +885,8 @@ func formatToB(i int, v string) string {
return fmt.Sprintf("%.2f", f)
}
// formatToC provides function to convert original string to special format as
// string type by given built-in number formats code and cell string.
// formatToC provides a function to convert original string to special format
// as string type by given built-in number formats code and cell string.
func formatToC(i int, v string) string {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -894,8 +896,8 @@ func formatToC(i int, v string) string {
return fmt.Sprintf("%d%%", int(f))
}
// formatToD provides function to convert original string to special format as
// string type by given built-in number formats code and cell string.
// formatToD provides a function to convert original string to special format
// as string type by given built-in number formats code and cell string.
func formatToD(i int, v string) string {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -905,8 +907,8 @@ func formatToD(i int, v string) string {
return fmt.Sprintf("%.2f%%", f)
}
// formatToE provides function to convert original string to special format as
// string type by given built-in number formats code and cell string.
// formatToE provides a function to convert original string to special format
// as string type by given built-in number formats code and cell string.
func formatToE(i int, v string) string {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -915,17 +917,17 @@ func formatToE(i int, v string) string {
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
// yyyy with 2006. These are in a specific order, due to the fact that m is used
// in month, minute, and am/pm. It would be easier to fix that with regular
// expressions, but if it's possible to keep this simple it would be easier to
// maintain. Full-length month and days (e.g. March, Tuesday) have letters in
// them that would be replaced by other characters below (such as the 'h' in
// March, or the 'd' in Tuesday) below. First we convert them to arbitrary
// characters unused in Excel Date formats, and then at the end, turn them to
// what they should actually be.
// Based off: http://www.ozgrid.com/Excel/CustomFormats.htm
// yyyy with 2006. These are in a specific order, due to the fact that m is
// used in month, minute, and am/pm. It would be easier to fix that with
// regular expressions, but if it's possible to keep this simple it would be
// easier to maintain. Full-length month and days (e.g. March, Tuesday) have
// letters in them that would be replaced by other characters below (such as
// the 'h' in March, or the 'd' in Tuesday) below. First we convert them to
// arbitrary characters unused in Excel Date formats, and then at the end,
// turn them to what they should actually be. Based off:
// http://www.ozgrid.com/Excel/CustomFormats.htm
func parseTime(i int, v string) string {
f, err := strconv.ParseFloat(v, 64)
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")
}
// 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.
func (f *File) stylesReader() *xlsxStyleSheet {
if f.Styles == nil {
@ -994,7 +996,7 @@ func (f *File) stylesReader() *xlsxStyleSheet {
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.
func (f *File) styleSheetWriter() {
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.
func parseFormatStyleSet(style string) (*formatStyle, error) {
format := formatStyle{
@ -1013,8 +1015,8 @@ func parseFormatStyleSet(style string) (*formatStyle, error) {
return &format, err
}
// NewStyle provides function to create style for cells by given style format.
// Note that the color field uses RGB color code.
// NewStyle provides a function to create style for cells by given style
// format. Note that the color field uses RGB color code.
//
// 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
}
// NewConditionalStyle provides function to create style for conditional format
// by given style format. The parameters are the same as function NewStyle().
// Note that the color field uses RGB color code and only support to set font,
// fills, alignment and borders currently.
// NewConditionalStyle provides a function to create style for conditional
// format by given style format. The parameters are the same as function
// NewStyle(). Note that the color field uses RGB color code and only support
// to set font, fills, alignment and borders currently.
func (f *File) NewConditionalStyle(style string) (int, error) {
s := f.stylesReader()
fs, err := parseFormatStyleSet(style)
@ -1935,7 +1937,8 @@ func (f *File) NewConditionalStyle(style string) (int, error) {
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 {
fontUnderlineType := map[string]string{"single": "single", "double": "double"}
if formatStyle.Font.Size < 1 {
@ -1963,8 +1966,8 @@ func setFont(formatStyle *formatStyle) *font {
return &f
}
// setNumFmt provides function to check if number format code in the range of
// built-in values.
// setNumFmt provides a function to check if number format code in the range
// of built-in values.
func setNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
dp := "0."
numFmtID := 164 // Default custom number format code from 164.
@ -2011,7 +2014,7 @@ func setNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
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 {
nf := xlsxNumFmt{FormatCode: *formatStyle.CustomNumFmt}
if style.NumFmts != nil {
@ -2029,7 +2032,7 @@ func setCustomNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
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 {
numFmts, ok := langNumFmt[formatStyle.Lang]
if !ok {
@ -2056,8 +2059,8 @@ func setLangNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int {
return nf.NumFmtID
}
// setFills provides function to add fill elements in the styles.xml by given
// cell format settings.
// setFills provides a function to add fill elements in the styles.xml by
// given cell format settings.
func setFills(formatStyle *formatStyle, fg bool) *xlsxFill {
var patterns = []string{
"none",
@ -2137,9 +2140,10 @@ func setFills(formatStyle *formatStyle, fg bool) *xlsxFill {
return &fill
}
// setAlignment provides function to formatting information pertaining to text
// alignment in cells. There are a variety of choices for how text is aligned
// both horizontally and vertically, as well as indentation settings, and so on.
// setAlignment provides a function to formatting information pertaining to
// text alignment in cells. There are a variety of choices for how text is
// aligned both horizontally and vertically, as well as indentation settings,
// and so on.
func setAlignment(formatStyle *formatStyle) *xlsxAlignment {
var alignment xlsxAlignment
if formatStyle.Alignment != nil {
@ -2156,7 +2160,7 @@ func setAlignment(formatStyle *formatStyle) *xlsxAlignment {
return &alignment
}
// setProtection provides function to set protection properties associated
// setProtection provides a function to set protection properties associated
// with the cell.
func setProtection(formatStyle *formatStyle) *xlsxProtection {
var protection xlsxProtection
@ -2167,7 +2171,7 @@ func setProtection(formatStyle *formatStyle) *xlsxProtection {
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.
func setBorders(formatStyle *formatStyle) *xlsxBorder {
var styles = []string{
@ -2219,7 +2223,7 @@ func setBorders(formatStyle *formatStyle) *xlsxBorder {
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.
func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment, applyProtection bool, alignment *xlsxAlignment, protection *xlsxProtection) int {
var xf xlsxXf
@ -2246,9 +2250,10 @@ func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, a
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
// 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:
//
@ -2352,9 +2357,10 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
}
}
// SetConditionalFormat provides function to create conditional formatting rule
// for cell value. Conditional formatting is a feature of Excel which allows you
// to apply a format to a cell or a range of cells based on certain criteria.
// SetConditionalFormat provides a function to create conditional formatting
// rule for cell value. Conditional formatting is a feature of Excel which
// 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.
// Allowable type values and their associated parameters are:
@ -2606,9 +2612,9 @@ func (f *File) SetConditionalFormat(sheet, area, formatSet string) error {
return err
}
// drawCondFmtCellIs provides function to create conditional formatting rule for
// cell value (include between, not between, equal, not equal, greater than and
// less than) by given priority, criteria type and format settings.
// drawCondFmtCellIs provides a function to create conditional formatting rule
// for cell value (include between, not between, equal, not equal, greater
// than and less than) by given priority, criteria type and format settings.
func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule {
c := &xlsxCfRule{
Priority: p + 1,
@ -2629,8 +2635,8 @@ func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule
return c
}
// drawCondFmtTop10 provides function to create conditional formatting rule for
// top N (default is top 10) by given priority, criteria type and format
// drawCondFmtTop10 provides a function to create conditional formatting rule
// for top N (default is top 10) by given priority, criteria type and format
// settings.
func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule {
c := &xlsxCfRule{
@ -2647,9 +2653,9 @@ func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule {
return c
}
// drawCondFmtAboveAverage provides function to create conditional formatting
// rule for above average and below average by given priority, criteria type and
// format settings.
// drawCondFmtAboveAverage provides a function to create conditional
// formatting rule for above average and below average by given priority,
// criteria type and format settings.
func drawCondFmtAboveAverage(p int, ct string, format *formatConditional) *xlsxCfRule {
return &xlsxCfRule{
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
// type and format settings.
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
// for color scale (include 2 color scale and 3 color scale) by given priority,
// criteria type and format settings.
// drawCondFmtColorScale provides a function to create conditional formatting
// rule for color scale (include 2 color scale and 3 color scale) by given
// priority, criteria type and format settings.
func drawCondFmtColorScale(p int, ct string, format *formatConditional) *xlsxCfRule {
minValue := format.MinValue
if minValue == "" {
@ -2708,8 +2714,8 @@ func drawCondFmtColorScale(p int, ct string, format *formatConditional) *xlsxCfR
return c
}
// drawCondFmtDataBar provides function to create conditional formatting rule
// for data bar by given priority, criteria type and format settings.
// drawCondFmtDataBar provides a function to create conditional formatting
// rule for data bar by given priority, criteria type and format settings.
func drawCondFmtDataBar(p int, ct string, format *formatConditional) *xlsxCfRule {
return &xlsxCfRule{
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
// expression by given priority, criteria type and format settings.
// drawConfFmtExp provides a function to create conditional formatting rule
// for expression by given priority, criteria type and format settings.
func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule {
return &xlsxCfRule{
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 {
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.
func (f *File) themeReader() *xlsxTheme {
var theme xlsxTheme

View File

@ -9,7 +9,7 @@ import (
"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.
func parseFormatTableSet(formatSet string) (*formatTable, error) {
format := formatTable{
@ -75,8 +75,8 @@ func (f *File) AddTable(sheet, hcell, vcell, format string) error {
return err
}
// countTables provides function to get table files count storage in the folder
// xl/tables.
// countTables provides a function to get table files count storage in the
// folder xl/tables.
func (f *File) countTables() int {
count := 0
for k := range f.XLSX {
@ -87,7 +87,7 @@ func (f *File) countTables() int {
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.
func (f *File) addSheetTable(sheet string, rID int) {
xlsx := f.workSheetReader(sheet)
@ -101,8 +101,8 @@ func (f *File) addSheetTable(sheet string, rID int) {
xlsx.TableParts.TableParts = append(xlsx.TableParts.TableParts, table)
}
// addTable provides function to add table by given worksheet name, coordinate
// area and format set.
// addTable provides a function to add table by given worksheet name,
// coordinate area and format set.
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.
if hyAxis == vyAxis {
@ -157,7 +157,7 @@ func (f *File) addTable(sheet, tableXML string, hxAxis, hyAxis, vxAxis, vyAxis,
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.
func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
format := formatAutoFilter{}
@ -264,7 +264,7 @@ func (f *File) AutoFilter(sheet, hcell, vcell, format string) error {
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.
func (f *File) autoFilter(sheet, ref string, refRange, hxAxis int, formatSet *formatAutoFilter) error {
xlsx := f.workSheetReader(sheet)
@ -301,8 +301,8 @@ func (f *File) autoFilter(sheet, ref string, refRange, hxAxis int, formatSet *fo
return nil
}
// writeAutoFilter provides function to check for single or double custom filters
// as default filters and handle them accordingly.
// writeAutoFilter provides a function to check for single or double custom
// filters as default filters and handle them accordingly.
func (f *File) writeAutoFilter(filter *xlsxAutoFilter, exp []int, tokens []string) {
if len(exp) == 1 && exp[0] == 2 {
// 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) {
operators := map[int]string{
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
// conditional expression into 1 or 2 sub expressions for further parsing.
// parseFilterExpression provides a function to converts the tokens of a
// possibly conditional expression into 1 or 2 sub expressions for further
// parsing.
//
// Examples:
//
@ -394,7 +395,7 @@ func (f *File) parseFilterExpression(expression string, tokens []string) ([]int,
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.
func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, string, error) {
operators := map[string]int{