golang excel导出时需要显示刷新

"github.com/xuri/excelize/v2"包导出excel文件时在调用WriteTo函数前需要显式关闭流写入器

if err := sw.Flush(); err != nil {

return nil, err

}

,否则会造成excel文件使用excel打开时出现问题,但是用wps打开文件就没有此问题

详细代码:

f := excelize.NewFile()

sw, err := f.NewStreamWriter(f.GetSheetName(sheetItemsIndex))

if err != nil {

return

}

defer sw.Flush()

sheet2Index = t.writeItemsToExcel(ctx, sw, traces, lang, sheet2Index, minId, maxId)

if err := sw.Flush(); err != nil {

return nil, err

}

var buf bytes.Buffer

_, _ = f.WriteTo(&buf)

相关推荐
为思念酝酿的痛3 小时前
POSIX信号量
linux·运维·服务器·后端
小羊在睡觉3 小时前
力扣84. 柱状图中最大的矩形
后端·算法·leetcode·golang·go
AI玫瑰助手3 小时前
Python函数:默认参数的定义与注意事项
开发语言·python·信息可视化
油炸自行车3 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
肩上风骋3 小时前
C++14特性
开发语言·c++·c++14特性
swipe4 小时前
Neo4j + Graph RAG 医疗知识图谱工程实践:患者教育问答真正需要的是“关系可追溯”
后端·langchain·llm
源码宝4 小时前
MES系统源码:Java8 + SpringBoot2.7 + MySQL8 + Redis,后端源码清爽易扩展
java·后端·源码·springboot·mes系统·源码二开·mes源码
JAVA社区5 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展
弥树子5 小时前
踩坑记录:服务器内网调用接口,真实请求URL与官方公开URL不一致问题排查
开发语言·php
金銀銅鐵5 小时前
[Java] 如何理解 class 文件中方法的 descriptor?
java·后端