Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV import to Grid, 1st row header
#2
I have a basic csv file that is structured like this
the first row is a header

ZIP,LAT,LNG
601,18.180555,-66.749961
602,18.361945,-67.175597
603,18.455183,-67.119887
606,18.158345,-66.932911
...
...
...

the file has has 33145  lines
 
Function DialogCSV_with_Header_To_QmGrid
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 QM_Grid 0x56031041 0x200 0 0 220 110 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3"
str qmg3x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,ICsv v._create; ICsv v1._create
,v.Separator=","; v1.Separator=","
,v.FromFile("$documents$\deskfiles\geocodebyzip.csv");; change to file location
,int nr=v.RowCount
,int nc=v.ColumnCount
,str ms
,v.GetRowMS(0 ms);; get header row data
,v1.AddRowMS(-1 nc ms);; add to second Csv variable
,str s2; v1.ToString(s2);;convert to string so can add columns
,s2.findreplace("," "[]");; format string so ColumnsAdd function will work
,;g.ColumnsAdd(s2 1);;add columns to grid adjusting width  assuming there will be vertical scrollbar.
,g.ColumnsAdd(s2);; just add columns to grid will adjust  width later used in conjunction with line33
,v.RemoveRow(0);;remove header row from Csv
,v.ToQmGrid(g);; load csv into grid now that header row is removed
,g.ColumnsWidthAdjust;;adjust column width now ( used with g.ColummsAdd(s2) comment out if not needed)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


Messages In This Thread
CSV import to Grid, 1st row header - by ilcaa - 10-13-2020, 01:14 AM
RE: CSV import to Grid, 1st row header - by Kevin - 10-16-2020, 01:37 PM
RE: CSV import to Grid, 1st row header - by ilcaa - 10-16-2020, 02:14 PM

Forum Jump:


Users browsing this thread: 4 Guest(s)