Private SQTbl As SQL
Private wb As PoiWorkbook
Private ws As PoiSheet
Private row As PoiRow
Dim SenderFilter As Object = SQTbl.ExecQueryAsync("SQL", "SELECT a.* from CNT_GET_MONTHLY_SLS(2015,5) a", Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, RS As ResultSet)
If Success Then
Private RowNo = 6,i = 1 As Int
If wb.IsInitialized = False Then
wb.InitializeExisting(File.DirApp,"CntRcpMonthlySls.xlsx","")
ws = wb.GetSheet(0)
End If
Do While RS.NextRow
row = ws.CreateRow(RowNo)
row.CreateCellString(0,RS.GetString("REGION"))
row.CreateCellString(1,RS.GetString("AREA"))
row.CreateCellString(2,RS.GetString("CTY"))
row.CreateCellString(3,RS.GetString("KOORD"))
row.CreateCellString(4,RS.GetString("DEPT"))
row.CreateCellString(5,RS.GetString("CD"))
row.CreateCellString(6,RS.GetString("COUNTER"))
row.CreateCellString(7,RS.GetString("SB_GRP"))
row.CreateCellString(8,RS.GetString("GRP"))
row.CreateCellString(9,RS.GetString("PRD_YR"))
row.CreateCellString(10,RS.GetString("ART"))
row.CreateCellString(11,RS.GetString("CL"))
row.CreateCellNumeric(12,RS.GetInt("Y1M1"))
row.CreateCellNumeric(13,RS.GetInt("Y1M2"))
row.CreateCellNumeric(14,RS.GetInt("Y1M3"))
row.CreateCellNumeric(15,RS.GetInt("Y1M4"))
row.CreateCellNumeric(16,RS.GetInt("Y1M5"))
row.CreateCellNumeric(17,RS.GetInt("Y1M6"))
row.CreateCellNumeric(18,RS.GetInt("Y1M7"))
row.CreateCellNumeric(19,RS.GetInt("Y1M8"))
row.CreateCellNumeric(20,RS.GetInt("Y1M9"))
row.CreateCellNumeric(21,RS.GetInt("Y1M10"))
row.CreateCellNumeric(22,RS.GetInt("Y1M11"))
row.CreateCellNumeric(23,RS.GetInt("Y1M12"))
row.CreateCellNumeric(24,RS.GetInt("Y2M1"))
row.CreateCellNumeric(25,RS.GetInt("Y2M2"))
row.CreateCellNumeric(26,RS.GetInt("Y2M3"))
row.CreateCellNumeric(27,RS.GetInt("Y2M4"))
row.CreateCellNumeric(28,RS.GetInt("Y2M5"))
row.CreateCellNumeric(29,RS.GetInt("Y2M6"))
row.CreateCellNumeric(30,RS.GetInt("Y2M7"))
row.CreateCellNumeric(31,RS.GetInt("Y2M8"))
row.CreateCellNumeric(32,RS.GetInt("Y2M9"))
row.CreateCellNumeric(33,RS.GetInt("Y2M10"))
row.CreateCellNumeric(34,RS.GetInt("Y2M11"))
row.CreateCellNumeric(35,RS.GetInt("Y2M12"))
row.CreateCellNumeric(36,RS.GetInt("Y3M1"))
row.CreateCellNumeric(37,RS.GetInt("Y3M2"))
row.CreateCellNumeric(38,RS.GetInt("Y3M3"))
row.CreateCellNumeric(39,RS.GetInt("Y3M4"))
row.CreateCellNumeric(40,RS.GetInt("Y3M5"))
row.CreateCellNumeric(41,RS.GetInt("Y3M6"))
row.CreateCellNumeric(42,RS.GetInt("Y3M7"))
row.CreateCellNumeric(43,RS.GetInt("Y3M8"))
row.CreateCellNumeric(44,RS.GetInt("Y3M9"))
row.CreateCellNumeric(45,RS.GetInt("Y3M10"))
row.CreateCellNumeric(46,RS.GetInt("Y3M11"))
row.CreateCellNumeric(47,RS.GetInt("Y3M12"))
row.CreateCellNumeric(48,RS.GetInt("TTL"))
RowNo = RowNo + 1
i = i+1
Loop
RS.Close
Else
Log(LastException)
End If
'Total
row = ws.CreateRow(RowNo)
row.CreateCellString(0,"")
row.CreateCellString(1,"")
row.CreateCellString(2,"")
row.CreateCellString(3,"")
row.CreateCellString(4,"")
row.CreateCellString(5,"")
row.CreateCellString(6,"")
row.CreateCellString(7,"")
row.CreateCellString(8,"")
row.CreateCellString(9,"")
row.CreateCellString(10,"")
row.CreateCellString(11,"")
row.CreateCellFormula(12,$"sum($M7:$M${RowNo})"$)
row.CreateCellFormula(13,$"sum($N7:$N${RowNo})"$)
row.CreateCellFormula(14,$"sum($O7:$O${RowNo})"$)
row.CreateCellFormula(15,$"sum($P7:$P${RowNo})"$)
row.CreateCellFormula(16,$"sum($Q7:$Q${RowNo})"$)
row.CreateCellFormula(17,$"sum($R7:$R${RowNo})"$)
row.CreateCellFormula(18,$"sum($S7:$S${RowNo})"$)
row.CreateCellFormula(19,$"sum($T7:$T${RowNo})"$)
row.CreateCellFormula(20,$"sum($U7:$U${RowNo})"$)
row.CreateCellFormula(21,$"sum($V7:$V${RowNo})"$)
row.CreateCellFormula(22,$"sum($W7:$W${RowNo})"$)
row.CreateCellFormula(23,$"sum($X7:$X${RowNo})"$)
row.CreateCellFormula(24,$"sum($Y7:$Y${RowNo})"$)
row.CreateCellFormula(25,$"sum($Z7:$Z${RowNo})"$)
row.CreateCellFormula(26,$"sum($AA7:$AA${RowNo})"$)
row.CreateCellFormula(27,$"sum($AB7:$AB${RowNo})"$)
row.CreateCellFormula(28,$"sum($AC7:$AC${RowNo})"$)
row.CreateCellFormula(29,$"sum($AD7:$AD${RowNo})"$)
row.CreateCellFormula(30,$"sum($AE7:$AE${RowNo})"$)
row.CreateCellFormula(31,$"sum($AF7:$AF${RowNo})"$)
row.CreateCellFormula(32,$"sum($AG7:$AG${RowNo})"$)
row.CreateCellFormula(33,$"sum($AH7:$AH${RowNo})"$)
row.CreateCellFormula(34,$"sum($AI7:$AI${RowNo})"$)
row.CreateCellFormula(35,$"sum($AJ7:$AJ${RowNo})"$)
row.CreateCellFormula(36,$"sum($AK7:$AK${RowNo})"$)
row.CreateCellFormula(37,$"sum($AL7:$AL${RowNo})"$)
row.CreateCellFormula(38,$"sum($AM7:$AM${RowNo})"$)
row.CreateCellFormula(39,$"sum($AN7:$AN${RowNo})"$)
row.CreateCellFormula(40,$"sum($AO7:$AO${RowNo})"$)
row.CreateCellFormula(41,$"sum($AP7:$AP${RowNo})"$)
row.CreateCellFormula(42,$"sum($AQ7:$AQ${RowNo})"$)
row.CreateCellFormula(43,$"sum($AR7:$AR${RowNo})"$)
row.CreateCellFormula(44,$"sum($AS7:$AS${RowNo})"$)
row.CreateCellFormula(45,$"sum($AT7:$AT${RowNo})"$)
row.CreateCellFormula(46,$"sum($AU7:$AU${RowNo})"$)
row.CreateCellFormula(47,$"sum($AV7:$AV${RowNo})"$)
row.CreateCellFormula(48,$"sum($AW7:$AW${RowNo})"$)
Private BorderSum As PoiCellStyle
If BorderSum.IsInitialized = False Then BorderSum.Initialize(wb)
BorderSum.BorderTop = BorderSum.BORDER_DOUBLE
BorderSum.BorderBottom = BorderSum.BORDER_DOUBLE
BorderSum.BorderLeft = BorderSum.BORDER_THIN
BorderSum.BorderRight = BorderSum.BORDER_THIN
For i = 0 To 48
row.GetCell(i).CellStyle = BorderSum
Next
DateTime.DateFormat= "MMddyy"
DateTime.TimeFormat="HHmmss"
Private stDateTime="_" & DateTime.Date(DateTime.Now) & "_" & DateTime.Time(DateTime.now) As String
FName = "Rpt" & stDateTime & ".xlsx"
wb.Save(File.DirApp,FName)
fx.ShowExternalDocument(File.GetUri(File.DirApp, FName))