I am trying to take data from one excel file (a) to another (b). The two files are different templates, when I copy the data from (b) to (a), I then save (a) to a new file name (c) so that I can use (a) as a template again.
After I save the file, as I would expect (c) to now appear as (a) with data from (b), instead (c) is unreadable and I see the message
"Excel found unreadable contents in "...."
Further message is provided upon opening the file
"Removed Records: Style from /xl/styles.xml part (Styles)"
Can someone see what I am missing or doing incorrectly to cause this issue?
Thank you
package main
import (
"fmt"
"github.com/tealeg/xlsx"
"time"
)
func main(){
//Read data from v2 template
var inputSlice [][][]string
inputSlice, errRead := xlsx.FileToSlice("v2_template.xlsx")
if errRead != nil{
fmt.Println("failed to read file")
}
//open v1 template file for writing
var outputFileTemplate, errOpen = xlsx.OpenFile("v1_template.xlsx")
if errOpen != nil{
fmt.Println("failed to open file")
}
accountSheet := outputFileTemplate.Sheet["Account"]
indx := 2
for a,sheet := range inputSlice[0][4:][:] {
if a < len(inputSlice)+1 { //check if first field has value
accountSheet.AddRowAtIndex(indx)
accountSheet.Rows[indx].AddCell()
accountSheet.Rows[indx].Cells[0].SetString(sheet[:][0])
}
}
//save output file
t := time.Now()
outfile := "final_v1.xlsx"
outputFilename := t.Format("./20060102150405") + "_" + outfile
//see if it is readable
outputFileTemplate.Save(outputFilename)
}
Here are the sheets I am using for this code here:
(a) https://drive.google.com/file/d/1Rh16Zanknbke-segnn_GZx7j8mGczmKL/view?usp=sharing (b) https://drive.google.com/file/d/1sRWRzsofvmzsP2LdYae3p7baVtekE0Wr/view?usp=sharing