anyone knows how to pull data from CSV file that uploaded as multipart.file based on its column and then input the data to another CSV file (the template)?
I still can't get the right logic to do that in golang. this is the csv file look alike:
"Coorporate",,,
Address :,,,
Boulevard Street,,,
Service / Office : 021-62318113 / 021-22684901,,,
"VGA WITH GUARANTEE",Dealer,Msrp,MARGIN
VGA-1,"37,000","38,000","1,000"
VGA-2,"27,500","28,500","1,000"
CASE ,Dealer ,Msrp ,MARGIN
CASE-1 ,"430,000","480,000","50,000"
CASE-2 ,"450,000","500,000","50,000"
"MAXSUN VGA ",Dealer ,Msrp ,MARGIN
MVGA-1,"13,300,000","13,800,000","500,000"
these are the codes I've tried to read to detect the table header (the row that at least having "Msrp" column):
reader := csv.NewReader(f)
records, err := reader.ReadAll()
var rows []string
columns := []string{"Msrp", "MSRP", "msrp"}
for _, column := range columns {
for _, columnName := range records {
for _, cols := range columnName {
if cols == column {
row := strings.Join(columnName, " ")
rows = append(rows, row)
break
}
}
}
but it just return the table header only. I need to get the value for each column and save it into a new slice (maybe?) so that later I can update the CSV template file with the value that I just pull from the CSV file uploaded
and let's say i have a struct :
type columnName struct {
PartName string json:"part_name"
Price int json:"price"
Msrp int json:"msrp"
}
how do i match the column name to that struct?
is there any better way to solve this problem?
anyway I'm new to golang and programming pls help me
many thanks!
Looks like there might be some confusion regarding the return of
reader := csv.NewReader(f). Thereaderrepresents the entire table. If you loop through thereader,you can print each line one by one.like this, write a test and print out the data,you will have a clear understanding.
hope this can help you