Compare commits
2 Commits
022240f8d3
...
4b6d0c744d
Author | SHA1 | Date | |
---|---|---|---|
|
4b6d0c744d | ||
|
99905a9341 |
48
FL.bas
48
FL.bas
@ -14,8 +14,6 @@ Public Enum ColorTier
|
|||||||
O_rganic = 7
|
O_rganic = 7
|
||||||
W_axtough = 8
|
W_axtough = 8
|
||||||
End Enum
|
End Enum
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Sub Determine_Active_Range()
|
Sub Determine_Active_Range()
|
||||||
@ -59,7 +57,7 @@ Sub Cross_Join_Selection()
|
|||||||
End If
|
End If
|
||||||
i = i + 1
|
i = i + 1
|
||||||
Next ar
|
Next ar
|
||||||
|
|
||||||
dest = InputBox("Input row & column numbers like ""3,17""")
|
dest = InputBox("Input row & column numbers like ""3,17""")
|
||||||
|
|
||||||
If dest = "" Then
|
If dest = "" Then
|
||||||
@ -614,13 +612,43 @@ Sub markdown_whole_sheet()
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
Sub sql_from_range()
|
Sub sql_from_range_db2_qh()
|
||||||
|
|
||||||
Dim x As New TheBigOne
|
Dim x As New TheBigOne
|
||||||
Dim wapi As New Windows_API
|
Dim wapi As New Windows_API
|
||||||
Dim r() As String
|
Dim r() As String
|
||||||
Selection.CurrentRegion.Select
|
Selection.CurrentRegion.Select
|
||||||
Call wapi.ClipBoard_SetData(x.SQLp_build_sql_values(x.ARRAYp_get_range_string(Selection), True, True, Db2))
|
Call wapi.ClipBoard_SetData(x.SQLp_build_sql_values(x.ARRAYp_get_range_string(Selection), True, True, Db2, True))
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub sql_from_range_db2_noqh()
|
||||||
|
|
||||||
|
Dim x As New TheBigOne
|
||||||
|
Dim wapi As New Windows_API
|
||||||
|
Dim r() As String
|
||||||
|
Selection.CurrentRegion.Select
|
||||||
|
Call wapi.ClipBoard_SetData(x.SQLp_build_sql_values(x.ARRAYp_get_range_string(Selection), True, True, Db2, False))
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub sql_from_range_pg_qh()
|
||||||
|
|
||||||
|
Dim x As New TheBigOne
|
||||||
|
Dim wapi As New Windows_API
|
||||||
|
Dim r() As String
|
||||||
|
Selection.CurrentRegion.Select
|
||||||
|
Call wapi.ClipBoard_SetData(x.SQLp_build_sql_values(x.ARRAYp_get_range_string(Selection), True, True, PostgreSQL, True))
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub sql_from_range_pg_noqh()
|
||||||
|
|
||||||
|
Dim x As New TheBigOne
|
||||||
|
Dim wapi As New Windows_API
|
||||||
|
Dim r() As String
|
||||||
|
Selection.CurrentRegion.Select
|
||||||
|
Call wapi.ClipBoard_SetData(x.SQLp_build_sql_values(x.ARRAYp_get_range_string(Selection), True, True, PostgreSQL, False))
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
@ -822,7 +850,7 @@ Sub extract_price_matrix()
|
|||||||
|
|
||||||
'-------------------------prepare sql to upload---------------------------------------------------------------
|
'-------------------------prepare sql to upload---------------------------------------------------------------
|
||||||
|
|
||||||
sql = x.SQLp_build_sql_values(unp, False, True, Db2)
|
sql = x.SQLp_build_sql_values(unp, False, True, Db2, False)
|
||||||
sql = "DECLARE GLOBAL TEMPORARY TABLE session.plbuild AS (" & sql & ") WITH DATA"
|
sql = "DECLARE GLOBAL TEMPORARY TABLE session.plbuild AS (" & sql & ") WITH DATA"
|
||||||
Call wapi.ClipBoard_SetData(sql)
|
Call wapi.ClipBoard_SetData(sql)
|
||||||
|
|
||||||
@ -918,15 +946,23 @@ Sub go_to_price_issue()
|
|||||||
Dim trow As Long
|
Dim trow As Long
|
||||||
Dim tcol As Long
|
Dim tcol As Long
|
||||||
Dim i As Long
|
Dim i As Long
|
||||||
|
Dim has_Pricesheet As Boolean
|
||||||
|
|
||||||
|
has_Pricesheet = False
|
||||||
For Each ws In Application.Worksheets
|
For Each ws In Application.Worksheets
|
||||||
For Each cp In ws.CustomProperties
|
For Each cp In ws.CustomProperties
|
||||||
If cp.Name = "spec_name" And cp.value = "price_list" Then
|
If cp.Name = "spec_name" And cp.value = "price_list" Then
|
||||||
Set price_sheet = ws
|
Set price_sheet = ws
|
||||||
|
has_Pricesheet = True
|
||||||
End If
|
End If
|
||||||
Next cp
|
Next cp
|
||||||
Next ws
|
Next ws
|
||||||
|
|
||||||
|
If Not has_Pricesheet Then
|
||||||
|
MsgBox ("no price sheet found")
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
Set orig = Application.Selection
|
Set orig = Application.Selection
|
||||||
|
|
||||||
Selection.CurrentRegion.Select
|
Selection.CurrentRegion.Select
|
||||||
|
@ -2274,7 +2274,7 @@ Function MISCe_col_to_letter(ByRef x As Long) As String
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, headers As Boolean, syntax As SQLsyntax) As String
|
Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, headers As Boolean, syntax As SQLsyntax, ByRef quote_headers As Boolean) As String
|
||||||
|
|
||||||
|
|
||||||
Dim i As Long
|
Dim i As Long
|
||||||
@ -2284,6 +2284,17 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
|||||||
Dim type_flag() As String
|
Dim type_flag() As String
|
||||||
Dim col_name As String
|
Dim col_name As String
|
||||||
Dim start_row As Long
|
Dim start_row As Long
|
||||||
|
Dim rx As Object
|
||||||
|
Dim strip_text As String
|
||||||
|
Dim strip_num As String
|
||||||
|
Dim strip_date As String
|
||||||
|
|
||||||
|
Set rx = CreateObject("vbscript.regexp")
|
||||||
|
rx.Global = True
|
||||||
|
|
||||||
|
strip_text = "[^a-zA-Z0-9 \-\_\,\#\""]"
|
||||||
|
strip_num = "[^0-9\.]"
|
||||||
|
strip_date = "[^0-9\\\-\:\.]"
|
||||||
|
|
||||||
ReDim type_flag(UBound(tbl, 1))
|
ReDim type_flag(UBound(tbl, 1))
|
||||||
For j = 0 To UBound(tbl, 1)
|
For j = 0 To UBound(tbl, 1)
|
||||||
@ -2306,16 +2317,22 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
|||||||
End If
|
End If
|
||||||
Next j
|
Next j
|
||||||
|
|
||||||
|
rx.Pattern = strip_text
|
||||||
If headers Then
|
If headers Then
|
||||||
start_row = 1
|
start_row = 1
|
||||||
For i = 0 To UBound(tbl, 1)
|
For i = 0 To UBound(tbl, 1)
|
||||||
If i > 0 Then col_name = col_name & ","
|
If i > 0 Then col_name = col_name & ","
|
||||||
col_name = col_name & tbl(i, 0)
|
If quote_headers Then
|
||||||
|
col_name = col_name & """" & rx.Replace(tbl(i, 0), "") & """"
|
||||||
|
Else
|
||||||
|
col_name = col_name & rx.Replace(tbl(i, 0), "")
|
||||||
|
End If
|
||||||
Next i
|
Next i
|
||||||
Else
|
Else
|
||||||
start_row = 0
|
start_row = 0
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|
||||||
For i = start_row To UBound(tbl, 2)
|
For i = start_row To UBound(tbl, 2)
|
||||||
rec = ""
|
rec = ""
|
||||||
If i <> start_row Then sql = sql & "," & vbCrLf
|
If i <> start_row Then sql = sql & "," & vbCrLf
|
||||||
@ -2324,35 +2341,40 @@ Public Function SQLp_build_sql_values(ByRef tbl() As String, trim As Boolean, he
|
|||||||
If j <> 0 Then rec = rec & ","
|
If j <> 0 Then rec = rec & ","
|
||||||
Select Case type_flag(j)
|
Select Case type_flag(j)
|
||||||
Case "N" '-------N = numeric but should probably be N for numeric----
|
Case "N" '-------N = numeric but should probably be N for numeric----
|
||||||
|
rx.Pattern = strip_num
|
||||||
If tbl(j, i) = "" Then
|
If tbl(j, i) = "" Then
|
||||||
rec = rec & "CAST(NULL AS NUMERIC)"
|
rec = rec & "CAST(NULL AS NUMERIC)"
|
||||||
Else
|
Else
|
||||||
rec = rec & Replace(Replace(tbl(j, i), "'", "''"), ",", "")
|
rec = rec & rx.Replace(tbl(j, i), "")
|
||||||
End If
|
End If
|
||||||
Case "S" '-------S = string------------------------------------------
|
Case "S" '-------S = string------------------------------------------
|
||||||
|
rx.Pattern = strip_text
|
||||||
If LTrim(RTrim(tbl(j, i))) = "" Then
|
If LTrim(RTrim(tbl(j, i))) = "" Then
|
||||||
rec = rec & "CAST(NULL AS VARCHAR(255))"
|
rec = rec & "CAST(NULL AS VARCHAR(255))"
|
||||||
Else
|
Else
|
||||||
If trim Then
|
If trim Then
|
||||||
rec = rec & "'" & LTrim(RTrim(Replace(tbl(j, i), "'", "''"))) & "'"
|
rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'"
|
||||||
Else
|
Else
|
||||||
rec = rec & "'" & Replace(tbl(j, i), "'", "''") & "'"
|
rec = rec & "'" & rx.Replace(tbl(j, i), "") & "'"
|
||||||
|
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
Case "D" '-------D = date---------------------------------------------
|
Case "D" '-------D = date---------------------------------------------
|
||||||
|
rx.Pattern = strip_date
|
||||||
If LTrim(RTrim(tbl(j, i))) = "" Then
|
If LTrim(RTrim(tbl(j, i))) = "" Then
|
||||||
rec = rec & "CAST(NULL AS DATE)"
|
rec = rec & "CAST(NULL AS DATE)"
|
||||||
Else
|
Else
|
||||||
rec = rec & "CAST('" & tbl(j, i) & "' AS DATE)"
|
rec = rec & "CAST('" & rx.Replace(tbl(j, i), "") & "' AS DATE)"
|
||||||
End If
|
End If
|
||||||
Case Else '-------Assume text------------------------------------------
|
Case Else '-------Assume text------------------------------------------
|
||||||
|
rx.Pattern = strip_text
|
||||||
If LTrim(RTrim(tbl(j, i))) = "" Then
|
If LTrim(RTrim(tbl(j, i))) = "" Then
|
||||||
rec = rec & "CAST(NULL AS VARCHAR(255))"
|
rec = rec & "CAST(NULL AS VARCHAR(255))"
|
||||||
Else
|
Else
|
||||||
If trim Then
|
If trim Then
|
||||||
rec = rec & "'" & LTrim(RTrim(Replace(tbl(j, i), "'", "''"))) & "'"
|
rec = rec & "'" & LTrim(RTrim(rx.Replace(tbl(j, i), ""))) & "'"
|
||||||
Else
|
Else
|
||||||
rec = rec & "'" & Replace(tbl(j, i), "'", "''") & "'"
|
rec = rec & "'" & rx.Replace(tbl(j, i), "") & "'"
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
End Select
|
End Select
|
||||||
|
Loading…
Reference in New Issue
Block a user