-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SetCellRichText is called multiple times on the same cell will increase the file size #787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I fixed this bug cell.go -> SetCellRichText func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
ws, err := f.workSheetReader(sheet)
if err != nil {
return err
}
cellData, col, _, err := f.prepareCell(ws, sheet, cell)
if err != nil {
return err
}
cellData.S = f.prepareCellStyle(ws, col, cellData.S)
si := xlsxSI{}
sst := f.sharedStringsReader()
textRuns := []xlsxR{}
for _, textRun := range runs {
run := xlsxR{T: &xlsxT{Val: textRun.Text}}
if strings.ContainsAny(textRun.Text, "\r\n ") {
run.T.Space = xml.Attr{Name: xml.Name{Space: NameSpaceXML, Local: "space"}, Value: "preserve"}
}
fnt := textRun.Font
if fnt != nil {
rpr := xlsxRPr{}
if fnt.Bold {
rpr.B = " "
}
if fnt.Italic {
rpr.I = " "
}
if fnt.Strike {
rpr.Strike = " "
}
if fnt.Underline != "" {
rpr.U = &attrValString{Val: &fnt.Underline}
}
if fnt.Family != "" {
rpr.RFont = &attrValString{Val: &fnt.Family}
}
if fnt.Size > 0.0 {
rpr.Sz = &attrValFloat{Val: &fnt.Size}
}
if fnt.Color != "" {
rpr.Color = &xlsxColor{RGB: getPaletteColor(fnt.Color)}
}
run.RPr = &rpr
}
textRuns = append(textRuns, run)
}
si.R = textRuns
if cellData.V == "" {
sst.SI = append(sst.SI, si)
sst.Count++
sst.UniqueCount++
cellData.T, cellData.V = "s", strconv.Itoa(len(sst.SI)-1)
} else {
siIndex, err := strconv.Atoi(cellData.V)
if nil != err {
return err
}
sst.SI[siIndex] = si
}
// NOTICE: this is bug
// sst.SI = append(sst.SI, si)
return err
} |
Hi @tonny-zhang, thanks for your issue. I think we need to check deep equal before appending rich text string items ( for idx, strItem := range sst.SI {
if reflect.DeepEqual(strItem, si) {
cellData.T, cellData.V = "s", strconv.Itoa(idx)
return err
}
} |
@xuri I add Extra fields to xlsxC for flag richtext type "rt", In order to distinguish from SetCellValue use string |
I have fixed it, please try to use the master branch code, and this patch will be released in the next version. |
This closes qax-os#787, avoid duplicate rich text string items, new formula…
…ormula fn: BIN2DEC, BIN2HEX, BIN2OCT, HEX2BIN, HEX2DEC, HEX2OCT, OCT2BIN, OCT2DEC, OCT2HEX
I found the result excel file size increased after I called multiple times method SetCellRichText on same cell
Steps to reproduce the issue:
ls -las *.xlsx
Describe the results you received:
Describe the results you expected:
Output of
go version
:Excelize version or commit ID:
Environment details (OS, Microsoft Excel™ version, physical, etc.):
The text was updated successfully, but these errors were encountered: