Comments (2)
I encountered an issue while working with Excel files. Specifically, when I read a Date type cell (including its style), modify some values, and then write it to another Excel file using
SetCellStr
andSetCellStyle
, the date cell in the new Excel file appears as a number. However, the cell value remains a string. If I attempt to edit the cell, its value changes to a number reflecting an Excel date day.During debugging, I observed that the
GetCellStyle
function calls theextractNumFmt
function to read the NumFmt from Excel, and thexf.NumFmtID
property has the correct value forCustomNumFmt
(like 178 foryyyy/mmmm
etc.).The problem seems to occur because the range
s.NumFmts.NumFmt
does not correctly find the appropriate NumFmt forstyle.NumFmt
, leading to the value error.To resolve this, I added a piece of code to stop the loop when it finds the correct NumFmtID. This adjustment corrected the issue for various formats, such as currency, date, and precision.
Here’s the modified code:
func (f *File) extractNumFmt(xf xlsxXf, s *xlsxStyleSheet, style *Style) { if xf.NumFmtID != nil { numFmtID := *xf.NumFmtID if _, ok := builtInNumFmt[numFmtID]; ok || isLangNumFmt(numFmtID) { style.NumFmt = numFmtID return } if s.NumFmts != nil { for _, numFmt := range s.NumFmts.NumFmt { // HERE IS THE CODE!!! LOOK AT ME! LOOK AT ME! if numFmt.NumFmtID == numFmtID { style.NumFmt = numFmtID style.CustomNumFmt = &numFmt.FormatCode break } // HERE IS THE CODE!!! LOOK AT ME! LOOK AT ME! style.CustomNumFmt = &numFmt.FormatCode if strings.Contains(numFmt.FormatCode, ";[Red]") { style.NegRed = true } for numFmtID, fmtCode := range currencyNumFmt { if style.NegRed { fmtCode += ";[Red]" + fmtCode } if numFmt.FormatCode == fmtCode { style.NumFmt = numFmtID } } } } } }
By the way, my version is v2.8.0
from excelize.
Ha, you fix it. thanks
from excelize.
Related Issues (20)
- Does doughnut chart support fill different color? HOT 1
- Same base code produces different fill colors for different version 2.8.1& 2.8.0 HOT 4
- Can excelize support obtaining cross sheet data validation dropdown options? HOT 1
- dingtalk xlsx file cannot GetPivotTables
- Setting Cell to NaN leads to "problem with some content" dialog in Excel HOT 1
- How to use *excelize.File.Close HOT 2
- Inserting rows removes macro assignment in button for ONLYOFFICE HOT 3
- Adding Picture into a merged cell is unable to adjust the alignment in the cell HOT 5
- Min and max values not respected on secondary Y axis if hidden with None:true HOT 1
- Insertrows returning row number exceeds maximum limit error HOT 8
- Is there any possible GetCellFormula faster? HOT 2
- Issue getting estyle from GetStyle function HOT 6
- how to set pivot filed format
- how to set pivot column format HOT 1
- Can't used negative numbers when I wanna to generate a chart
- Can't used negative numbers when I wanna generate a chart HOT 6
- GetConditionalFormats do not return cell only Conditional Formating HOT 3
- SetSheetVisible for datagrip export excel, will panic: runtime error: invalid memory address or nil pointer dereference HOT 1
- Is it possible any way to write or read xls format ? HOT 1
- [HELP] control characters inputs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from excelize.