Skip to content

Commit

Permalink
Format code, update documentation and remove exported variable `XMLHe…
Browse files Browse the repository at this point in the history
…aderByte`
  • Loading branch information
xuri committed Mar 23, 2022
1 parent 139ee4c commit 8a33522
Show file tree
Hide file tree
Showing 36 changed files with 330 additions and 328 deletions.
366 changes: 186 additions & 180 deletions calc.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion calc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4629,7 +4629,7 @@ func TestCalcLogBeta(t *testing.T) {
}

func TestCalcBetainvProbIterator(t *testing.T) {
assert.Equal(t, 1.0, betainvProbIterator(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, true))
assert.Equal(t, 1.0, betainvProbIterator(1, 1, 1, 1, 1, 1, 1, 1, 1))
}

func TestNestedFunctionsWithOperators(t *testing.T) {
Expand Down
55 changes: 26 additions & 29 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (f *File) setCellTimeFunc(sheet, axis string, value time.Time) error {
if err != nil {
return err
}
cellData, col, row, err := f.prepareCell(ws, sheet, axis)
cellData, col, row, err := f.prepareCell(ws, axis)
if err != nil {
return err
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (f *File) SetCellInt(sheet, axis string, value int) error {
if err != nil {
return err
}
cellData, col, row, err := f.prepareCell(ws, sheet, axis)
cellData, col, row, err := f.prepareCell(ws, axis)
if err != nil {
return err
}
Expand All @@ -276,7 +276,7 @@ func (f *File) SetCellBool(sheet, axis string, value bool) error {
if err != nil {
return err
}
cellData, col, row, err := f.prepareCell(ws, sheet, axis)
cellData, col, row, err := f.prepareCell(ws, axis)
if err != nil {
return err
}
Expand All @@ -299,7 +299,7 @@ func setCellBool(value bool) (t string, v string) {
return
}

// SetCellFloat sets a floating point value into a cell. The prec parameter
// SetCellFloat sets a floating point value into a cell. The precision parameter
// specifies how many places after the decimal will be shown while -1 is a
// special value that will use as many decimal places as necessary to
// represent the number. bitSize is 32 or 64 depending on if a float32 or
Expand All @@ -308,26 +308,26 @@ func setCellBool(value bool) (t string, v string) {
// var x float32 = 1.325
// f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
//
func (f *File) SetCellFloat(sheet, axis string, value float64, prec, bitSize int) error {
func (f *File) SetCellFloat(sheet, axis string, value float64, precision, bitSize int) error {
ws, err := f.workSheetReader(sheet)
if err != nil {
return err
}
cellData, col, row, err := f.prepareCell(ws, sheet, axis)
cellData, col, row, err := f.prepareCell(ws, axis)
if err != nil {
return err
}
ws.Lock()
defer ws.Unlock()
cellData.S = f.prepareCellStyle(ws, col, row, cellData.S)
cellData.T, cellData.V = setCellFloat(value, prec, bitSize)
cellData.T, cellData.V = setCellFloat(value, precision, bitSize)
return err
}

// setCellFloat prepares cell type and string type cell value by a given
// float value.
func setCellFloat(value float64, prec, bitSize int) (t string, v string) {
v = strconv.FormatFloat(value, 'f', prec, bitSize)
func setCellFloat(value float64, precision, bitSize int) (t string, v string) {
v = strconv.FormatFloat(value, 'f', precision, bitSize)
return
}

Expand All @@ -338,7 +338,7 @@ func (f *File) SetCellStr(sheet, axis, value string) error {
if err != nil {
return err
}
cellData, col, row, err := f.prepareCell(ws, sheet, axis)
cellData, col, row, err := f.prepareCell(ws, axis)
if err != nil {
return err
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func (f *File) SetCellDefault(sheet, axis, value string) error {
if err != nil {
return err
}
cellData, col, row, err := f.prepareCell(ws, sheet, axis)
cellData, col, row, err := f.prepareCell(ws, axis)
if err != nil {
return err
}
Expand Down Expand Up @@ -478,7 +478,7 @@ type FormulaOpts struct {
}

// SetCellFormula provides a function to set formula on the cell is taken
// according to the given worksheet name (case sensitive) and cell formula
// according to the given worksheet name (case-sensitive) and cell formula
// settings. The result of the formula cell can be calculated when the
// worksheet is opened by the Office Excel application or can be using
// the "CalcCellValue" function also can get the calculated cell value. If
Expand Down Expand Up @@ -560,7 +560,7 @@ func (f *File) SetCellFormula(sheet, axis, formula string, opts ...FormulaOpts)
if err != nil {
return err
}
cellData, _, _, err := f.prepareCell(ws, sheet, axis)
cellData, _, _, err := f.prepareCell(ws, axis)
if err != nil {
return err
}
Expand Down Expand Up @@ -672,12 +672,9 @@ type HyperlinkOpts struct {

// 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. Maximum limit hyperlinks in a worksheet is 65530. This
// function is only used to set the hyperlink of the cell and doesn't affect
// the value of the cell. If you need to set the value of the cell, please use
// the other functions such as `SetCellStyle` or `SetSheetRow`. The below is
// example for external link.
// hyperlink "External" for website or "Location" for moving to one of cell
// in this workbook. Maximum limit hyperlinks in a worksheet is 65530. The
// below is example for external link.
//
// if err := f.SetCellHyperLink("Sheet1", "A3",
// "https://github.com/xuri/excelize", "External"); err != nil {
Expand All @@ -692,7 +689,7 @@ type HyperlinkOpts struct {
// }
// err = f.SetCellStyle("Sheet1", "A3", "A3", style)
//
// A this is another example for "Location":
// This is another example for "Location":
//
// err := f.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
//
Expand Down Expand Up @@ -759,7 +756,7 @@ func (f *File) GetCellRichText(sheet, cell string) (runs []RichTextRun, err erro
if err != nil {
return
}
cellData, _, _, err := f.prepareCell(ws, sheet, cell)
cellData, _, _, err := f.prepareCell(ws, cell)
if err != nil {
return
}
Expand Down Expand Up @@ -940,7 +937,7 @@ func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
if err != nil {
return err
}
cellData, col, row, err := f.prepareCell(ws, sheet, cell)
cellData, col, row, err := f.prepareCell(ws, cell)
if err != nil {
return err
}
Expand All @@ -950,7 +947,7 @@ func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
cellData.S = f.prepareCellStyle(ws, col, row, cellData.S)
si := xlsxSI{}
sst := f.sharedStringsReader()
textRuns := []xlsxR{}
var textRuns []xlsxR
totalCellChars := 0
for _, textRun := range runs {
totalCellChars += len(textRun.Text)
Expand Down Expand Up @@ -1000,8 +997,8 @@ func (f *File) SetSheetRow(sheet, axis string, slice interface{}) error {

for i := 0; i < v.Len(); i++ {
cell, err := CoordinatesToCellName(col+i, row)
// Error should never happens here. But keep checking to early detect regresions
// if it will be introduced in future.
// Error should never happen here. But keep checking to early detect regressions
// if it will be introduced in the future.
if err != nil {
return err
}
Expand All @@ -1013,7 +1010,7 @@ func (f *File) SetSheetRow(sheet, axis string, slice interface{}) error {
}

// getCellInfo does common preparation for all SetCell* methods.
func (f *File) prepareCell(ws *xlsxWorksheet, sheet, cell string) (*xlsxC, int, int, error) {
func (f *File) prepareCell(ws *xlsxWorksheet, cell string) (*xlsxC, int, int, error) {
var err error
cell, err = f.mergeCellsParser(ws, cell)
if err != nil {
Expand Down Expand Up @@ -1175,7 +1172,7 @@ func (f *File) checkCellInArea(cell, area string) (bool, error) {
return cellInRef([]int{col, row}, coordinates), err
}

// cellInRef provides a function to determine if a given range is within an
// cellInRef provides a function to determine if a given range is within a
// range.
func cellInRef(cell, ref []int) bool {
return cell[0] >= ref[0] && cell[0] <= ref[2] && cell[1] >= ref[1] && cell[1] <= ref[3]
Expand Down Expand Up @@ -1241,7 +1238,7 @@ func parseSharedFormula(dCol, dRow int, orig []byte) (res string, start int) {
// considered to be the same when their respective representations in
// R1C1-reference notation, are the same.
//
// Note that this function not validate ref tag to check the cell if or not in
// Note that this function not validate ref tag to check the cell whether in
// allow area, and always return origin shared formula.
func getSharedFormula(ws *xlsxWorksheet, si int, axis string) string {
for _, r := range ws.SheetData.Row {
Expand All @@ -1264,7 +1261,7 @@ func getSharedFormula(ws *xlsxWorksheet, si int, axis string) string {
}

// shiftCell returns the cell shifted according to dCol and dRow taking into
// consideration of absolute references with dollar sign ($)
// consideration absolute references with dollar sign ($)
func shiftCell(cellID string, dCol, dRow int) string {
fCol, fRow, _ := CellNameToCoordinates(cellID)
signCol, signRow := "", ""
Expand Down
2 changes: 1 addition & 1 deletion cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestConcurrency(t *testing.T) {
assert.NoError(t, f.SetSheetRow("Sheet1", "B6", &[]interface{}{
" Hello",
[]byte("World"), 42, int8(1<<8/2 - 1), int16(1<<16/2 - 1), int32(1<<32/2 - 1),
int64(1<<32/2 - 1), float32(42.65418), float64(-42.65418), float32(42), float64(42),
int64(1<<32/2 - 1), float32(42.65418), -42.65418, float32(42), float64(42),
uint(1<<32 - 1), uint8(1<<8 - 1), uint16(1<<16 - 1), uint32(1<<32 - 1),
uint64(1<<32 - 1), true, complex64(5 + 10i),
}))
Expand Down
2 changes: 1 addition & 1 deletion chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ func (f *File) AddChartSheet(sheet, format string, combo ...string) error {
// getFormatChart provides a function to check format set of the chart and
// create chart format.
func (f *File) getFormatChart(format string, combo []string) (*formatChart, []*formatChart, error) {
comboCharts := []*formatChart{}
var comboCharts []*formatChart
formatSet, err := parseFormatChartSet(format)
if err != nil {
return formatSet, comboCharts, err
Expand Down
2 changes: 1 addition & 1 deletion chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func TestChartWithLogarithmicBase(t *testing.T) {
}
assert.True(t, ok, "Can't open the %s", chartPath)

err = xml.Unmarshal([]byte(xmlCharts[i]), &chartSpaces[i])
err = xml.Unmarshal(xmlCharts[i], &chartSpaces[i])
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down
21 changes: 9 additions & 12 deletions col.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ type Cols struct {
sheetXML []byte
}

// GetCols return all the columns in a sheet by given worksheet name (case
// sensitive). For example:
// GetCols return all the columns in a sheet by given worksheet name (case-sensitive). For example:
//
// cols, err := f.GetCols("Sheet1")
// if err != nil {
Expand Down Expand Up @@ -240,20 +239,18 @@ func (f *File) Cols(sheet string) (*Cols, error) {
// visible, err := f.GetColVisible("Sheet1", "D")
//
func (f *File) GetColVisible(sheet, col string) (bool, error) {
visible := true
colNum, err := ColumnNameToNumber(col)
if err != nil {
return visible, err
return true, err
}

ws, err := f.workSheetReader(sheet)
if err != nil {
return false, err
}
if ws.Cols == nil {
return visible, err
return true, err
}

visible := true
for c := range ws.Cols.Col {
colData := &ws.Cols.Col[c]
if colData.Min <= colNum && colNum <= colData.Max {
Expand Down Expand Up @@ -455,12 +452,12 @@ func (f *File) SetColStyle(sheet, columns string, styleID int) error {
// f := excelize.NewFile()
// err := f.SetColWidth("Sheet1", "A", "H", 20)
//
func (f *File) SetColWidth(sheet, startcol, endcol string, width float64) error {
min, err := ColumnNameToNumber(startcol)
func (f *File) SetColWidth(sheet, startCol, endCol string, width float64) error {
min, err := ColumnNameToNumber(startCol)
if err != nil {
return err
}
max, err := ColumnNameToNumber(endcol)
max, err := ColumnNameToNumber(endCol)
if err != nil {
return err
}
Expand Down Expand Up @@ -502,7 +499,7 @@ func (f *File) SetColWidth(sheet, startcol, endcol string, width float64) error
// flatCols provides a method for the column's operation functions to flatten
// and check the worksheet columns.
func flatCols(col xlsxCol, cols []xlsxCol, replacer func(fc, c xlsxCol) xlsxCol) []xlsxCol {
fc := []xlsxCol{}
var fc []xlsxCol
for i := col.Min; i <= col.Max; i++ {
c := deepcopy.Copy(col).(xlsxCol)
c.Min, c.Max = i, i
Expand Down Expand Up @@ -547,7 +544,7 @@ func flatCols(col xlsxCol, cols []xlsxCol, replacer func(fc, c xlsxCol) xlsxCol)
// | | | (x2,y2)|
// +-----+------------+------------+
//
// Example of an object that covers some of the area from cell A1 to B2.
// Example of an object that covers some area from cell A1 to B2.
//
// Based on the width and height of the object we need to calculate 8 vars:
//
Expand Down
2 changes: 1 addition & 1 deletion comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (f *File) GetComments() (comments map[string][]Comment) {
target = "xl" + strings.TrimPrefix(target, "..")
}
if d := f.commentsReader(strings.TrimPrefix(target, "/")); d != nil {
sheetComments := []Comment{}
var sheetComments []Comment
for _, comment := range d.CommentList.Comment {
sheetComment := Comment{}
if comment.AuthorID < len(d.Authors.Author) {
Expand Down
6 changes: 3 additions & 3 deletions crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func genISOPasswdHash(passwd, hashAlgorithm, salt string, spinCount int) (hashVa
err = ErrPasswordLengthInvalid
return
}
hash, ok := map[string]string{
algorithmName, ok := map[string]string{
"MD4": "md4",
"MD5": "md5",
"SHA-1": "sha1",
Expand All @@ -653,11 +653,11 @@ func genISOPasswdHash(passwd, hashAlgorithm, salt string, spinCount int) (hashVa
passwordBuffer, _ := encoder.Bytes([]byte(passwd))
b.Write(passwordBuffer)
// Generate the initial hash.
key := hashing(hash, b.Bytes())
key := hashing(algorithmName, b.Bytes())
// Now regenerate until spin count.
for i := 0; i < spinCount; i++ {
iterator := createUInt32LEBuffer(i, 4)
key = hashing(hash, key, iterator)
key = hashing(algorithmName, key, iterator)
}
hashValue, saltValue = base64.StdEncoding.EncodeToString(key), base64.StdEncoding.EncodeToString(s)
return
Expand Down
2 changes: 1 addition & 1 deletion crypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestEncryptionMechanism(t *testing.T) {
}

func TestHashing(t *testing.T) {
assert.Equal(t, hashing("unsupportedHashAlgorithm", []byte{}), []uint8([]byte(nil)))
assert.Equal(t, hashing("unsupportedHashAlgorithm", []byte{}), []byte(nil))
}

func TestGenISOPasswdHash(t *testing.T) {
Expand Down
Loading

0 comments on commit 8a33522

Please sign in to comment.