|
@@ -65,15 +65,14 @@ func lettersToNumeric(letters string) int {
|
|
|
return sum
|
|
return sum
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// Get the largestDenominator that is a multiple of a basedDenominator
|
|
// Get the largestDenominator that is a multiple of a basedDenominator
|
|
|
// and fits at least once into a given numerator.
|
|
// and fits at least once into a given numerator.
|
|
|
func getLargestDenominator(numerator, multiple, baseDenominator, power int) (int, int) {
|
|
func getLargestDenominator(numerator, multiple, baseDenominator, power int) (int, int) {
|
|
|
- if numerator / multiple == 0 {
|
|
|
|
|
|
|
+ if numerator/multiple == 0 {
|
|
|
return 1, power
|
|
return 1, power
|
|
|
}
|
|
}
|
|
|
next, nextPower := getLargestDenominator(
|
|
next, nextPower := getLargestDenominator(
|
|
|
- numerator, multiple * baseDenominator, baseDenominator, power + 1)
|
|
|
|
|
|
|
+ numerator, multiple*baseDenominator, baseDenominator, power+1)
|
|
|
if next > multiple {
|
|
if next > multiple {
|
|
|
return next, nextPower
|
|
return next, nextPower
|
|
|
}
|
|
}
|
|
@@ -86,7 +85,7 @@ func formatColumnName(colId []int) string {
|
|
|
lastPart := len(colId) - 1
|
|
lastPart := len(colId) - 1
|
|
|
|
|
|
|
|
result := ""
|
|
result := ""
|
|
|
- for n, part := range(colId) {
|
|
|
|
|
|
|
+ for n, part := range colId {
|
|
|
if n == lastPart {
|
|
if n == lastPart {
|
|
|
// The least significant number is in the
|
|
// The least significant number is in the
|
|
|
// range 0-25, all other numbers are 1-26,
|
|
// range 0-25, all other numbers are 1-26,
|
|
@@ -182,7 +181,7 @@ func getCoordsFromCellIDString(cellIDString string) (x, y int, error error) {
|
|
|
// getCellIDStringFromCoords returns the Excel format cell name that
|
|
// getCellIDStringFromCoords returns the Excel format cell name that
|
|
|
// represents a pair of zero based cartesian coordinates.
|
|
// represents a pair of zero based cartesian coordinates.
|
|
|
func getCellIDStringFromCoords(x, y int) string {
|
|
func getCellIDStringFromCoords(x, y int) string {
|
|
|
- letterPart := numericToLetters(x);
|
|
|
|
|
|
|
+ letterPart := numericToLetters(x)
|
|
|
numericPart := y + 1
|
|
numericPart := y + 1
|
|
|
return fmt.Sprintf("%s%d", letterPart, numericPart)
|
|
return fmt.Sprintf("%s%d", letterPart, numericPart)
|
|
|
}
|
|
}
|
|
@@ -245,8 +244,12 @@ func calculateMaxMinFromWorksheet(worksheet *xlsxWorksheet) (minx, miny, maxx, m
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if minx == maxVal { minx = 0 }
|
|
|
|
|
- if miny == maxVal { miny = 0 }
|
|
|
|
|
|
|
+ if minx == maxVal {
|
|
|
|
|
+ minx = 0
|
|
|
|
|
+ }
|
|
|
|
|
+ if miny == maxVal {
|
|
|
|
|
+ miny = 0
|
|
|
|
|
+ }
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -453,7 +456,7 @@ func readSheetsFromZipFile(f *zip.File, file *File, sheetXMLMap map[string]strin
|
|
|
return nil, nil, sheet.Error
|
|
return nil, nil, sheet.Error
|
|
|
}
|
|
}
|
|
|
sheetsByName[workbook.Sheets.Sheet[sheet.Index].Name] = sheet.Sheet
|
|
sheetsByName[workbook.Sheets.Sheet[sheet.Index].Name] = sheet.Sheet
|
|
|
- sheets[j] = sheet.Sheet
|
|
|
|
|
|
|
+ sheets[sheet.Index] = sheet.Sheet
|
|
|
}
|
|
}
|
|
|
return sheetsByName, sheets, nil
|
|
return sheetsByName, sheets, nil
|
|
|
}
|
|
}
|
|
@@ -468,7 +471,6 @@ func readSharedStringsFromZipFile(f *zip.File) (*RefTable, error) {
|
|
|
var decoder *xml.Decoder
|
|
var decoder *xml.Decoder
|
|
|
var reftable *RefTable
|
|
var reftable *RefTable
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// In a file with no strings it's possible that
|
|
// In a file with no strings it's possible that
|
|
|
// sharedStrings.xml doesn't exist. In this case the value
|
|
// sharedStrings.xml doesn't exist. In this case the value
|
|
|
// passed as f will be nil.
|
|
// passed as f will be nil.
|
|
@@ -523,36 +525,35 @@ type WorkBookRels map[string]string
|
|
|
func (w *WorkBookRels) MakeXLSXWorkbookRels() xlsxWorkbookRels {
|
|
func (w *WorkBookRels) MakeXLSXWorkbookRels() xlsxWorkbookRels {
|
|
|
relCount := len(*w)
|
|
relCount := len(*w)
|
|
|
xWorkbookRels := xlsxWorkbookRels{}
|
|
xWorkbookRels := xlsxWorkbookRels{}
|
|
|
- xWorkbookRels.Relationships = make([]xlsxWorkbookRelation, relCount + 2)
|
|
|
|
|
- for k, v := range(*w) {
|
|
|
|
|
- index, err := strconv.Atoi(k[3:len(k)])
|
|
|
|
|
|
|
+ xWorkbookRels.Relationships = make([]xlsxWorkbookRelation, relCount+2)
|
|
|
|
|
+ for k, v := range *w {
|
|
|
|
|
+ index, err := strconv.Atoi(k[3:])
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
panic(err.Error())
|
|
panic(err.Error())
|
|
|
}
|
|
}
|
|
|
- xWorkbookRels.Relationships[index -1] = xlsxWorkbookRelation{
|
|
|
|
|
- Id: k,
|
|
|
|
|
|
|
+ xWorkbookRels.Relationships[index-1] = xlsxWorkbookRelation{
|
|
|
|
|
+ Id: k,
|
|
|
Target: v,
|
|
Target: v,
|
|
|
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"}
|
|
|
|
|
|
|
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
relCount++
|
|
relCount++
|
|
|
sheetId := fmt.Sprintf("rId%d", relCount)
|
|
sheetId := fmt.Sprintf("rId%d", relCount)
|
|
|
- xWorkbookRels.Relationships[relCount -1] = xlsxWorkbookRelation{
|
|
|
|
|
- Id: sheetId,
|
|
|
|
|
- Target: "sharedStrings.xml",
|
|
|
|
|
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"}
|
|
|
|
|
|
|
+ xWorkbookRels.Relationships[relCount-1] = xlsxWorkbookRelation{
|
|
|
|
|
+ Id: sheetId,
|
|
|
|
|
+ Target: "sharedStrings.xml",
|
|
|
|
|
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"}
|
|
|
|
|
|
|
|
relCount++
|
|
relCount++
|
|
|
sheetId = fmt.Sprintf("rId%d", relCount)
|
|
sheetId = fmt.Sprintf("rId%d", relCount)
|
|
|
- xWorkbookRels.Relationships[relCount -1] = xlsxWorkbookRelation{
|
|
|
|
|
- Id: sheetId,
|
|
|
|
|
- Target: "styles.xml",
|
|
|
|
|
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"}
|
|
|
|
|
|
|
+ xWorkbookRels.Relationships[relCount-1] = xlsxWorkbookRelation{
|
|
|
|
|
+ Id: sheetId,
|
|
|
|
|
+ Target: "styles.xml",
|
|
|
|
|
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"}
|
|
|
|
|
|
|
|
return xWorkbookRels
|
|
return xWorkbookRels
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// readWorkbookRelationsFromZipFile is an internal helper function to
|
|
// readWorkbookRelationsFromZipFile is an internal helper function to
|
|
|
// extract a map of relationship ID strings to the name of the
|
|
// extract a map of relationship ID strings to the name of the
|
|
|
// worksheet.xml file they refer to. The resulting map can be used to
|
|
// worksheet.xml file they refer to. The resulting map can be used to
|
|
@@ -584,7 +585,6 @@ func readWorkbookRelationsFromZipFile(workbookRels *zip.File) (WorkBookRels, err
|
|
|
return sheetXMLMap, nil
|
|
return sheetXMLMap, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// ReadZip() takes a pointer to a zip.ReadCloser and returns a
|
|
// ReadZip() takes a pointer to a zip.ReadCloser and returns a
|
|
|
// xlsx.File struct populated with its contents. In most cases
|
|
// xlsx.File struct populated with its contents. In most cases
|
|
|
// ReadZip is not used directly, but is called internally by OpenFile.
|
|
// ReadZip is not used directly, but is called internally by OpenFile.
|