summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2015-12-08 16:38:26 +0100
committerJean-Pierre Ledure <jp@ledure.be>2015-12-08 16:38:26 +0100
commit04ebc52c262ea495abf1ed72e60656710504475b (patch)
tree98c7ffb2ea17028bc8f171591fb42c058e79012d /wizards
parentebafc4fef20944c9c0ba75fbea064bf285a73735 (diff)
Access2Base - DoCmd.OutputTo applicable to Calc, Excel and Text/csv formats
Database._OutputToCalc uses LO filters to export table and/or query data Change-Id: I69b15e76a490de32ec2cae73661f8ffd5f2b53b2
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/access2base/Database.xba105
-rw-r--r--wizards/source/access2base/DoCmd.xba8
-rw-r--r--wizards/source/access2base/acConstants.xba3
3 files changed, 102 insertions, 14 deletions
diff --git a/wizards/source/access2base/Database.xba b/wizards/source/access2base/Database.xba
index 8d524b627921..2398de89fd5f 100644
--- a/wizards/source/access2base/Database.xba
+++ b/wizards/source/access2base/Database.xba
@@ -591,7 +591,7 @@ Public Function OutputTo(ByVal pvObjectType As Variant _
, ByVal Optional pvEncoding As Variant _
, ByVal Optional pvQuality As Variant _
) As Boolean
-&apos;Supported: acFormatHTML for tables and queries
+&apos;Supported: acFormatHTML, acFormatODS, acFormatXLS, acFormatXLSX, acFormatTXT for tables and queries
If _ErrorHandler() Then On Local Error Goto Error_Function
Const cstThisSub = &quot;Database.OutputTo&quot;
@@ -607,8 +607,9 @@ Const cstThisSub = &quot;Database.OutputTo&quot;
If pvOutputFormat &lt;&gt; &quot;&quot; Then
If Not Utils._CheckArgument(UCase(pvOutputFormat), 3, vbString, Array( _
UCase(acFormatHTML), &quot;HTML&quot; _
- , UCase(acFormatXLS), &quot;XLS&quot; _
, UCase(acFormatODS), &quot;ODS&quot; _
+ , UCase(acFormatXLS), &quot;XLS&quot; _
+ , UCase(acFormatXLSX), &quot;XLSX&quot; _
, UCase(acFormatTXT), &quot;TXT&quot;, &quot;CSV&quot; _
, &quot;&quot;)) _
Then Goto Exit_Function &apos; A 2nd time to allow case unsensitivity
@@ -625,7 +626,7 @@ Const cstThisSub = &quot;Database.OutputTo&quot;
If Not Utils._CheckArgument(pvQuality, 7, _AddNumeric(), Array(acExportQualityPrint, acExportQualityScreen)) Then Goto Exit_Function
Dim sOutputFile As String, bFound As Boolean, i As Integer, iCount As Integer, oTable As Object
-Dim sOutputFormat As String, iTemplate As Integer, iOutputFile As Integer, bOutput As Boolean
+Dim sOutputFormat As String, iTemplate As Integer, iOutputFile As Integer, bOutput As Boolean, sSuffix As String
&apos;Find applicable table or query
bFound = False
If pvObjectType = acOutputTable Then iCount = TableDefs.Count Else iCount = Querydefs.Count
@@ -640,17 +641,21 @@ Dim sOutputFormat As String, iTemplate As Integer, iOutputFile As Integer, bOutp
&apos;Determine format and parameters
If pvOutputFormat = &quot;&quot; Then
- sOutputFormat = _PromptFormat(Array(&quot;HTML&quot;, &quot;ODS&quot;, &quot;XLS&quot;, &quot;TXT&quot;)) &apos; Prompt user for format
+ sOutputFormat = _PromptFormat(Array(&quot;HTML&quot;, &quot;ODS&quot;, &quot;XLS&quot;, &quot;XLSX&quot;, &quot;TXT&quot;)) &apos; Prompt user for format
If sOutputFormat = &quot;&quot; Then Goto Exit_Function
- If Not Utils._CheckArgument(UCase(sOutputFormat), 3, vbString, Array(UCase(acFormatHTML), &quot;HTML&quot;, &quot;&quot;)) _
- Then Goto Exit_Function &apos; Today only value, later maybe Calc ?
Else
sOutputFormat = UCase(pvOutputFormat)
End If
&apos;Determine output file
If pvOutputFile = &quot;&quot; Then &apos; Prompt file picker to user
- sSuffix = &quot;html&quot;
+ Select Case sOutputFormat
+ Case UCase(acFormatHTML), &quot;HTML&quot; : sSuffix = &quot;html&quot;
+ Case UCase(acFormatODS), &quot;ODS&quot; : sSuffix = &quot;ods&quot;
+ Case UCase(acFormatXLS), &quot;XLS&quot; : sSuffix = &quot;xls&quot;
+ Case UCase(acFormatXLSX), &quot;XLSX&quot; : sSuffix = &quot;xlsx&quot;
+ Case UCase(acFormatTXT), &quot;TXT&quot;, &quot;CSV&quot; : sSuffix = &quot;txt&quot;
+ End Select
sOutputFile = _PromptFilePicker(sSuffix)
If sOutputFile = &quot;&quot; Then Goto Exit_Function
Else
@@ -659,7 +664,18 @@ Dim sOutputFormat As String, iTemplate As Integer, iOutputFile As Integer, bOutp
sOutputFile = ConvertToURL(sOutputFile)
&apos;Create file
- bOutput = _OutputToHTML(oTable, sOutputFile, pvTemplateFile)
+ Select Case sOutputFormat
+ Case UCase(acFormatHTML), &quot;HTML&quot;
+ bOutput = _OutputToHTML(oTable, sOutputFile, pvTemplateFile)
+ Case UCase(acFormatODS), &quot;ODS&quot;
+ bOutput = _OutputToCalc(oTable, sOutputFile, acFormatODS)
+ Case UCase(acFormatXLS), &quot;XLS&quot;
+ bOutput = _OutputToCalc(oTable, sOutputFile, acFormatXLS)
+ Case UCase(acFormatXLS), &quot;XLSX&quot;
+ bOutput = _OutputToCalc(oTable, sOutputFile, acFormatXLSX)
+ Case UCase(acFormatTXT), &quot;TXT&quot;, &quot;CSV&quot;
+ bOutput = _OutputToCalc(oTable, sOutputFile, acFormatTXT)
+ End Select
oTable.Dispose()
&apos;Launch application, if requested
@@ -1159,14 +1175,14 @@ End Function &apos; _OutputNullToHTML V1.4.0
REM -----------------------------------------------------------------------------------------------------------------------
Private Function _OutputNumberToHTML(ByVal pvNumber As Variant, ByVal Optional piPrecision As Integer) As String
-&apos; Converts input date to HTML compatible string
+&apos; Converts input number to HTML compatible string
Dim vNumber As Variant
If IsMissing(piPrecision) Then piPrecision = -1
If pvNumber = Int(pvNumber) Then
vNumber = Int(pvNumber)
Else
- If piPrecision &gt;= 0 Then vNumber = (Int(pvNumber * 10 ^ piPrecision + 0.5)) / 10 ^ piPrecision Else vNumber = Int(pvNumber)
+ If piPrecision &gt;= 0 Then vNumber = (Int(pvNumber * 10 ^ piPrecision + 0.5)) / 10 ^ piPrecision Else vNumber = pvNumber
End If
_OutputNumberToHTML = Format(vNumber)
@@ -1264,6 +1280,75 @@ Dim i As Integer, l As Long
End Function &apos; _OutputStringToHTML V1.4.0
REM -----------------------------------------------------------------------------------------------------------------------
+Private Function _OutputToCalc(poData As Object, ByVal psOutputFile As String, psFilter As String) As Boolean
+&apos; https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Database_Import
+
+Dim oCalcDoc As Object, oSheet As Object, vWin As Variant
+Dim vImportDesc() As Variant, iSource As Integer
+Dim oRange As Object, i As Integer, iCol As Integer, oColumns As Object
+
+ If _ErrorHandler() Then On Local Error Goto Error_Function
+ _OutputToCalc = False
+ &apos; Create a new OO-Calc-Document
+ Set oCalcDoc = StarDesktop.LoadComponentFromURL( _
+ &quot;private:factory/scalc&quot; _
+ , &quot;_default&quot; ,0, Array() _
+ )
+
+ &apos; Get the unique spreadsheet
+ Set oSheet = oCalcDoc.Sheets(0)
+
+ &apos; Describe import
+ With poData
+ If ._Type = &quot;TABLEDEF&quot; Then
+ iSource = com.sun.star.sheet.DataImportMode.TABLE
+ Else
+ iSource = com.sun.star.sheet.DataImportMode.QUERY
+ End If
+ vImportDesc = Array( _
+ _MakePropertyValue(&quot;DatabaseName&quot;, URL) _
+ , _MakePropertyValue(&quot;SourceType&quot;, iSource) _
+ , _MakePropertyValue(&quot;SourceObject&quot;, ._Name) _
+ )
+ oSheet.Name = ._Name
+ End With
+
+ &apos; Import
+ oSheet.getCellByPosition(0, 0).doImport(vImportDesc())
+
+ Select Case psFilter
+ Case acFormatODS, acFormatXLS, acFormatXLSX &apos; Formatting
+ iCol = poData.Fields().Count
+ Set oRange = oSheet.getCellRangeByPosition(0, 0, iCol - 1, 0)
+ oRange.CharWeight = com.sun.star.awt.FontWeight.BOLD
+ oRange.CellBackColor = RGB(200, 200, 200)
+ oRange.HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
+ Set oColumns = oRange.getColumns()
+ For i = 0 To iCol - 1
+ oColumns.getByIndex(i).OptimalWidth = True
+ Next i
+ Case Else
+ End Select
+
+ oCalcDoc.storeAsUrl(psOutputFile, Array( _
+ _MakePropertyValue(&quot;FilterName&quot;, psFilter) _
+ , _MakePropertyValue(&quot;Overwrite&quot;, True) _
+ ))
+ oCalcDoc.close(False)
+ _OutputToCalc = True
+
+Exit_Function:
+ Set oColumns = Nothing
+ Set oRange = Nothing
+ Set oSheet = Nothing
+ Set oCalcDoc = Nothing
+ Exit Function
+Error_Function:
+ TraceError(TRACEABORT, ERRDFUNCTION, _A2B_.CalledSub, 0, , sSQL)
+ Goto Exit_Function
+End Function &apos; OutputToCalc V1.4.0
+
+REM -----------------------------------------------------------------------------------------------------------------------
Public Function _OutputToHTML(poTable As Object, ByVal psOutputFile As String, ByVal psTemplateFile As String) As Boolean
&apos; http://www.ehow.com/how_5652706_create-html-template-ms-access.html
diff --git a/wizards/source/access2base/DoCmd.xba b/wizards/source/access2base/DoCmd.xba
index d4f5706d51d2..ff3d5ae6b01c 100644
--- a/wizards/source/access2base/DoCmd.xba
+++ b/wizards/source/access2base/DoCmd.xba
@@ -1212,9 +1212,11 @@ Public Function OutputTo(ByVal pvObjectType As Variant _
, ByVal Optional pvEncoding As Variant _
, ByVal Optional pvQuality As Variant _
) As Boolean
+REM https://wiki.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0
REM https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
+REM https://msdn.microsoft.com/en-us/library/ms709353%28v=vs.85%29.aspx
&apos;Supported: acFormatPDF, acFormatODT, acFormatDOC, acFormatHTML for forms
-&apos; acFormatHTML, acFormatXLS, acFormatODS, acFormatTXT for tables and queries
+&apos; acFormatHTML, acFormatODS, acFormatXLS, acFormatXLSX, acFormatTXT for tables and queries
If _ErrorHandler() Then On Local Error Goto Error_Function
Const cstThisSub = &quot;OutputTo&quot;
@@ -1230,8 +1232,8 @@ Const cstThisSub = &quot;OutputTo&quot;
If pvOutputFormat &lt;&gt; &quot;&quot; Then
If Not Utils._CheckArgument(UCase(pvOutputFormat), 3, vbString, Array( _
UCase(acFormatPDF), UCase(acFormatODT), UCase(acFormatDOC), UCase(acFormatHTML) _
- , UCase(acFormatXLS), UCase(acFormatODS), UCase(acFormatTXT) _
- , &quot;PDF&quot;, &quot;ODT&quot;, &quot;DOC&quot;, &quot;HTML&quot;, &quot;XLS&quot;, &quot;ODS&quot;, &quot;TXT&quot;, &quot;CSV&quot;, &quot;&quot; _
+ , UCase(acFormatODS), UCase(acFormatXLS), UCase(acFormatXLSX), UCase(acFormatTXT) _
+ , &quot;PDF&quot;, &quot;ODT&quot;, &quot;DOC&quot;, &quot;HTML&quot;, &quot;ODS&quot;, &quot;XLS&quot;, &quot;XLSX&quot;, &quot;TXT&quot;, &quot;CSV&quot;, &quot;&quot; _
)) Then Goto Exit_Function &apos; A 2nd time to allow case unsensitivity
End If
If IsMissing(pvOutputFile) Then pvOutputFile = &quot;&quot;
diff --git a/wizards/source/access2base/acConstants.xba b/wizards/source/access2base/acConstants.xba
index 08e442a3c6eb..1a3db6a8e230 100644
--- a/wizards/source/access2base/acConstants.xba
+++ b/wizards/source/access2base/acConstants.xba
@@ -287,8 +287,9 @@ Global Const acFormatPDF = &quot;writer_pdf_Export&quot;
Global Const acFormatODT = &quot;writer8&quot;
Global Const acFormatDOC = &quot;MS Word 97&quot;
Global Const acFormatHTML = &quot;HTML&quot;
+Global Const acFormatODS = &quot;calc8&quot;
Global Const acFormatXLS = &quot;MS Excel 97&quot;
-Global Const acFormatODS = &quot;StarOffice XML (Calc)&quot;
+Global Const acFormatXLSX = &quot;Calc MS Excel 2007 XML&quot;
Global Const acFormatTXT = &quot;Text - txt - csv (StarCalc)&quot;
REM AcExportQuality