Go stringified sheet cells with fmt.Sprint, so a numeric VS read with UNFORMATTED_VALUE was rendered as 2.609767878e+09. Text columns of the payments sheet now go through sheets.CellString, which never uses exponent form; bank inference uses the same helper. Both sync implementations now append VS as a text cell so Sheets keeps it a string and leading zeros survive. Existing rows are not rewritten. Python already read VS as a digit string; a regression test pins that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
912 B
Go
34 lines
912 B
Go
package sheets
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
// CellString renders a cell read with UNFORMATTED_VALUE as text.
|
|
// Numeric cells arrive as float64; fmt.Sprint would print large ones in
|
|
// exponent form ("2.609767878e+09"), which corrupts identifiers such as VS
|
|
// or Bank ID. Mirrors get_str in legacy/scripts/match_payments.py.
|
|
func CellString(v any) string {
|
|
switch x := v.(type) {
|
|
case nil:
|
|
return ""
|
|
case string:
|
|
return x
|
|
case float64:
|
|
return strconv.FormatFloat(x, 'f', -1, 64)
|
|
}
|
|
return fmt.Sprint(v)
|
|
}
|
|
|
|
// TextCell marks s to be stored as text when written with USER_ENTERED:
|
|
// a leading apostrophe stops Sheets from parsing digits as a number (which
|
|
// would drop leading zeros). The apostrophe is not part of the stored value.
|
|
// Empty stays empty. Mirrors as_text_cell in legacy/scripts/sync_fio_to_sheets.py.
|
|
func TextCell(s string) string {
|
|
if s == "" {
|
|
return ""
|
|
}
|
|
return "'" + s
|
|
}
|