Comments (9)
Thanks for your issue. Which version of the Excelize library are you using? Could you follow the issue template and show us a complete, standalone example program or reproducible demo?
from excelize.
Thanks for your reply!
my steps to reproduce the issue:
- i have a producer process, read data from mysql, and transferring data to consumer processes through pipelines
- consumer processes receive data and and export it to xlsx,demo code:
func generateExcelColumn(n int) string {
result := ""
for n > 0 {
remainder := (n - 1) % 26
result = fmt.Sprintf("%c%s", 'A'+remainder, result)
n = (n - 1) / 26
}
return result
}
func generateExcelCell(column, row int) string {
columnName := generateExcelColumn(column)
cell := fmt.Sprintf("%s%d", columnName, row)
return cell
}
func export() {
file := excelize.NewFile()
_, err = file.NewSheet("Sheet1")
reader := bufio.NewReader(os.Stdin) // from producer process
for {
line, err = reader.ReadString('\n') // read a line
line = strings.TrimSuffix(line, "\n") // Remove line breaks at the end of a line
fields := strings.Split(line, "\t") // Separate fields by tab
for col, field := range fields {
cell := generateExcelCell(col+1, row)
transField := strings.Replace(field, "\\n", "\n", -1)
if err = file.SetCellValue("Sheet1", cell, transField); err != nil {
os.Exit(-1)
}
}
row++
}
}
the results you received:
When I opened it using WPS and found that a space would be added before the first data in the first column.
Also I get an error: strconv.ParseInt: parsing "\ufeff1": invalid syntax, "\ ufeff1" seems to represent a space.
By the way, only the data in the first row and first column will be added with this space, and other data will not be added.
Describe the results you expected:
I hope that when exporting xlsx, this space will not be added by default
Output of go version
:
GOVERSION="go1.19.13"
Excelize version:
"github.com/xuri/excelize/v2"
from excelize.
Thanks for your feedback. This duplicate with issue #1778, As the documentation of the SetCellValue
function says, it supports multiple data types. Please convert the transField
variable to Go's numeric data type (int, uint, float64, etc.) in your code before setting the cell value.
from excelize.
My issue may be different from #1778,non numeric data can also have this situation:
from excelize.
Could you follow the issue template and show us a complete, standalone example program or reproducible demo (with a main function)? Please check and confirm that the value of the variable transField
doesn't contain a blank character prefix.
from excelize.
I have a simple test:
3. I added a few lines for printing:
func generateExcelColumn(n int) string {
result := ""
for n > 0 {
remainder := (n - 1) % 26
result = fmt.Sprintf("%c%s", 'A'+remainder, result)
n = (n - 1) / 26
}
return result
}
func generateExcelCell(column, row int) string {
columnName := generateExcelColumn(column)
cell := fmt.Sprintf("%s%d", columnName, row)
return cell
}
func export() {
file := excelize.NewFile()
_, err = file.NewSheet("Sheet1")
reader := bufio.NewReader(os.Stdin) // from producer process
for {
line, err = reader.ReadString('\n') // read a line
logger.Infof(ctx, "-1--------------line:%s", line)
line = strings.TrimSuffix(line, "\n") // Remove line breaks at the end of a line
fields := strings.Split(line, "\t") // Separate fields by tab
for col, field := range fields {
logger.Infof(ctx, "-2--------------field:%s", field)
cell := generateExcelCell(col+1, row)
transField := strings.Replace(field, "\\n", "\n", -1)
logger.Infof(ctx, "-3--------------transField:%s", transField)
if err = file.SetCellValue("Sheet1", cell, transField); err != nil {
os.Exit(-1)
}
}
row++
}
}
Print results:
2024-02-04 18:39:37.069 [INFO] {c52f1bd66cc19d05628bd8bf27af3ad6} -1--------------line:Quién4 1
2024-02-04 18:39:37.069 [INFO] {c52f1bd66cc19d05628bd8bf27af3ad6} -2--------------field:Quién4
2024-02-04 18:39:37.069 [INFO] {c52f1bd66cc19d05628bd8bf27af3ad6} -3--------------transField:Quién4
From the print results, it can be seen that from line, err=reader ReadString ('\ n')
reads data without spaces, and the value of the variable transField doesn't contain a blank character prefix.
So, I guess, it looks like I missed some settings when using this package?
from excelize.
Could you remove the database and context-related code to simplify the code, and show us a complete, standalone example program? The demo should be with a main function to reproducible this problem by executing directly.
from excelize.
Seems to have found the problem.
i print with %q:
2024-02-04 19:55:58.175 [INFO] {c52f1bd66cc19d05628bd8bf27af3ad6} -1--------------line:"\ufeffQuien4\t1\n"
Quien4
has a special character before it....
emm, thanks for your help,
It seems like to be caused by the use of stdout or stdin....
from excelize.
You're welcome. Please close the issue if this problem has been resolved.
from excelize.
Related Issues (20)
- How to insert new data into an existing sheet table and preserve the previous data. HOT 1
- 为什么sheet不支持区分大小写?( Why does sheet not support case sensitivity?) HOT 3
- Generated Excel files lose content partially - Error on opening HOT 5
- Parentheses in formulas get cut out when inserting new columns or rows HOT 1
- Feature request: SetRowHeight for StreamWriter HOT 1
- Tab (\t) character cannot be displayed in the generated workbook's cell HOT 1
- condition A with style ,the unstyled condition will be applied with A's style. HOT 1
- excelize按行读取内容成字符串数组导致日期格式错误 HOT 1
- The first execution of Flush() data will be written to Excel, and SetRow() after Flush() will not take effect HOT 1
- duration has -1 second HOT 2
- Excel to PDF Page Size issue HOT 1
- After adding and saving images in Excel by excelize, the GetPictureCells method cannot read any values HOT 1
- Support insert the Kingsoft WPS Office embedded image cells via the DISPIMG formula function HOT 2
- [BUG] Get Rows function HOT 1
- Count columns and rows of the worksheets. 会提供 Max row Max col 属性吗 HOT 1
- Open a Microsoft Excel sheet which been set password, in code not provide “Options” cause “zip: not a valid zip file” HOT 2
- I have 70 option datas,but can't set dropList as datavalidation HOT 1
- Remove column caused workbook corrupted HOT 1
- Font size of the header and footer doesn't work HOT 2
- sw.SetRow() Can only be called once HOT 3
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.