Skip to content

Instantly share code, notes, and snippets.

@matteosuppo
Created July 1, 2019 13:06
Show Gist options
  • Save matteosuppo/fea6773b677832addf5524a268acf4bc to your computer and use it in GitHub Desktop.
Save matteosuppo/fea6773b677832addf5524a268acf4bc to your computer and use it in GitHub Desktop.
A simple way to convert the stupid .xls of Contoarancio to a more sensible .csv
package main
import (
"encoding/csv"
"os"
"golang.org/x/net/html"
)
func main() {
input, err := os.Open("contoarancio.xls")
if err != nil {
panic(err)
}
doc, err := html.Parse(input)
if err != nil {
panic(err)
}
output, err := os.Create("contoarancio.csv")
if err != nil {
panic(err)
}
defer output.Close()
writer := csv.NewWriter(output)
defer writer.Flush()
row := doc.FirstChild.FirstChild.NextSibling.FirstChild.FirstChild.FirstChild
for row != nil {
if row.FirstChild.FirstChild == nil {
break
}
dataContabile := row.FirstChild.FirstChild.Data
dataValuta := row.FirstChild.NextSibling.FirstChild.Data
causale := row.FirstChild.NextSibling.NextSibling.FirstChild.Data
descrizione := row.FirstChild.NextSibling.NextSibling.NextSibling.FirstChild.Data
importo := row.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.FirstChild.Data
writer.Write([]string{dataContabile, dataValuta, causale, descrizione, importo})
row = row.NextSibling
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment