<div dir="ltr"><div>Hey,</div><div><br></div><div>please ignore this email. The original email is about a GSoC project and not about macro progamming.</div><div><br></div><div>Kind regards,</div><div>Markus<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 22, 2019 at 12:12 AM sos <<a href="mailto:sos@pmg.be">sos@pmg.be</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div bgcolor="#FFFFFF">
<p>hallo,</p>
<p>you can import data into a spreadsheet in 2 ways</p>
<p>Fast = connecting the Calcdoc to a databasedoc and using buildin "Importer" service <span style="background-color:rgb(255,102,255)">oDBRange.getReferredCells.doImport(oDesc())</span></p>
<p>Slow = import cell by cell using a dataset or a array</p>
<p><span style="background-color:rgb(255,102,255)">fast</span><br>
</p>
<p>function ConnectCalc_to_DBdoc(Optional sqlcalc as String, sDocURL as String , optional sArea as string)<br>
        dim extt as string<br>
    extt = right(bstandnm , 3)<br>
    SearchFlags = com.sun.star.frame.FrameSearchFlag.CREATE +  com.sun.star.frame.FrameSearchFlag.ALL<br>
</p>
<p>    if ucase(extt) = "OTS" then 'calc template<br>
     Dim args(3) As New com.sun.star.beans.PropertyValue<br>
    Dim URL As String<br>
   ' URL = convertToUrl("T:\Template\TOOLS\Berichten_spreadsheet.ots")<br>
    URL = convertToUrl(sDocurl)<br>
    args(0).Name = "AsTemplate"<br>
    args(0).Value = True<br>
    args(1).Name = "MacroExecutionMode"<br>
    args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE_NO_WARN<br>
    args(2).Name = "FilterName"<br>
    args(2).Value = "calc8_template"<br>
    args(3).Name = "Hidden"<br>
    args(3).Value = false<br>
    ODS = StarDeskTop.LoadComponentFromUrl(URL, "_blank", 0, args())<br>
    else<br>
     ODS = StarDesktop.loadComponentFromURL("private:factory/scalc","_blank",SearchFlags,Array())<br>
       endif<br>
      <br>
    oSheet = ODS.Sheets.getByIndex(0)<br>
    if ismissing(sArea) then<br>
    sArea = "A1"<br>
    endif<br>
    area = osheet.getCellRangeByName(sArea).getRangeAddress()' adres is nodig, niet de range opzich<br>
    if not oDS.DatabaseRanges.hasByName("MyImport") then<br>
        oDS.DatabaseRanges.addNewByName("MyImport",area)<br>
    endif<br>
    oDBRange = oDS.DataBaseRanges.getByName("MyImport")<br>
    oDBcontext = CreateUnoService("com.sun.star.sdb.DatabaseContext")<br>
    if oDBcontext.hasbyname("mysql_native")then<br>
    oDBcontext.revokeDatabaseLocation("mysql_native")<br>
    endif<br>
  <br>
     oDBcontext.registerDatabaseLocation("mysql_native",converttoURL("\\your DBdoclocation")     
<br>
<br>
    oDB = oDBcontext.GetByName("mysql_native")<br>
    oDB.Password = "yourpassword"<br>
</p>
<p>'**** we make first a QUERY because a simple  SQLstring in the  ImportDescritor only works with  OO-SQL en not with a native SQL  (this is a bug)<br>
</p>
<p>    oQdefs = oDB.QueryDefinitions<br>
    oQ = createUnoService("com.sun.star.sdb.QueryDefinition") <br>
    oQ.EscapeProcessing = False<br>
    oQ.command = sqlcalc<br>
        If oQDefs.hasByName("calcdoc") Then <br>
              oQDefs.removeByName("calcdoc")', oQueryObject) <br>
           End If <br>
    oQDefs.insertByName("calcdoc", oQ) <br>
</p>
<p>    Dim oDesc(3) as new com.sun.star.beans.PropertyValue<br>
    oDesc(0).Name = "DatabaseName" <br>
    oDesc(0).Value = "mysql_native" <br>
    oDesc(1).Name = "SourceType" <br>
    oDesc(1).Value = com.sun.star.sheet.DataImportMode.QUERY<br>
    oDesc(2).Name = "SourceObject" <br>
    oDesc(2).Value = "calcdoc"<br>
 '   oDesc(3).Name = "IsNative"  'must been false  !<br>
  '  oDesc(3).Value = false<br>
    oDBRange.getReferredCells.doImport(oDesc())<br>
    oDBcontext.revokeDatabaseLocation("mysql_native")<br>
    oDS.DatabaseRanges.removeByName("MyImport")<br>
    <br>
    Dim FileProperties(1) As New com.sun.star.beans.PropertyValue<br>
    Url = <a class="gmail-m_-2681646493123287053moz-txt-link-rfc2396E">
"file:///"</a> & sDocurl<br>
       FileProperties(0).Name = "Overwrite"<br>
    FileProperties(0).Value = True<br>
        FileProperties(1).Name = "FilterName"<br>
    if lcase(extt) = "xls" then <br>
        FileProperties(1).Value = "MS Excel 97"<br>
    else<br>
        FileProperties(1).Value = ""<br>
    end if<br>
<br>
    If NOT IsMissing(sDocurl) and len(sDocurl) > 5 and ucase(right(sDocurl,3)) <> "OTS" Then<br>
        oDS.storeAsURL(Url, FileProperties())<br>
    end if<br>
    ConnectionviaDBdoc = ODS<br>
end FUNCTION<br>
</p>
<p><span style="background-color:rgb(255,102,255)">slow</span><br>
</p>
<p>Sub ResultSetToCalc(oResultGet)<br>
    Dim args(3) As New com.sun.star.beans.PropertyValue<br>
    args(1).Name = "MacroExecutionMode"<br>
    args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE_NO_WARN<br>
    args(2).name = "Hidden"<br>
    args(2).Value = true<br>
    ods = nothing<br>
    ODS = StarDesktop.LoadComponentFromUrl("private:factory/scalc","_default",0,args())<br>
    oSheet = ODS.Sheets.getByIndex(0)<br>
    oCellCursor = oSheet.createCursor()<br>
<br>
    xPos = 0<br>
    yPos = 3<br>
<br>
    For i = 0 To oResultGet.MetaData.ColumnCount - 1<br>
        Cell = oSheet.getCellByPosition(xPos + i, yPos)<br>
        Cell.String = oResultGet.MetaData.getColumnName(i+1)<br>
    Next i<br>
    oResultGet.beforeFirst()<br>
    while oResultGet.next()<br>
        yPos = yPos + 1<br>
        For i = 0 To oResultGet.MetaData.ColumnCount - 1<br>
            Cell = oSheet.getCellByPosition(xPos + i, yPos)<br>
            Cell.String = oResultGet.getString(oResultGet.findColumn(oResultGet.MetaData.getColumnName(i+1)))<br>
        Next i<br>
    wend<br>
<br>
    oCellCursor.gotoStartOfUsedArea(true)<br>
    oCellCursor.gotoEndOfUsedArea(true)<br>
    nFirstCol = oCellCursor.getRangeAddress().StartColumn<br>
    nLastCol = oCellCursor.getRangeAddress().EndColumn<br>
    nStartRow = oCellCursor.getRangeAddress().StartRow<br>
    nLastRow = oCellCursor.getRangeAddress().EndRow<br>
<br>
    oRange = oSheet.getCellRangeByPosition(nFirstCol, nStartRow, nLastCol, nStartRow)    'Rij met de kolomnamen<br>
    oRange.CharWeight = com.sun.star.awt.FontWeight.BOLD<br>
    oRange.CellBackColor = RGB(200,200,200)<br>
    oRange.HoriJustify = com.sun.star.table.CellHoriJustify.CENTER<br>
<br>
    oColumns = oRange.getColumns()<br>
    for i = 0 to nLastCol<br>
         oColumns.getByIndex( i ).optimalWidth = true<br>
    next<br>
<br>
    ODS.CurrentController.Frame.ContainerWindow.Visible = True<br>
<br>
End Sub<br>
</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="gmail-m_-2681646493123287053moz-cite-prefix">On 3/21/2019 6:47 AM, smooth_vaibhav wrote:<br>
</div>
<blockquote type="cite">
<pre class="gmail-m_-2681646493123287053moz-quote-pre">I have been keen about the project idea of implementing the import
functionality of external data in calc. I have some queries regarding it.

1) There are numerous possibilities of external data sources like database,
files. So should the implementation should be independent of external source
of data or is it the case that we first gonna store it in a ScDBdata.

2) Its given that the user can select the range of data to be selected and
imported. Does that imply we provide them with a UI such that they can
choose the number of columns and rows to be imported.

I acknowledge the fact that the Mail list is to be used just for important
purposes but I have some queries to clear for better understanding of the
project idea. 

Thanks.



--
Sent from: <a class="gmail-m_-2681646493123287053moz-txt-link-freetext" href="http://document-foundation-mail-archive.969070.n3.nabble.com/Dev-f1639786.html" target="_blank">http://document-foundation-mail-archive.969070.n3.nabble.com/Dev-f1639786.html</a>
_______________________________________________
LibreOffice mailing list
<a class="gmail-m_-2681646493123287053moz-txt-link-abbreviated" href="mailto:LibreOffice@lists.freedesktop.org" target="_blank">LibreOffice@lists.freedesktop.org</a>
<a class="gmail-m_-2681646493123287053moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/libreoffice" target="_blank">https://lists.freedesktop.org/mailman/listinfo/libreoffice</a></pre>
</blockquote>
</div>

_______________________________________________<br>
LibreOffice mailing list<br>
<a href="mailto:LibreOffice@lists.freedesktop.org" target="_blank">LibreOffice@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/libreoffice" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/libreoffice</a></blockquote></div>