<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Hi Markus<br>
    &nbsp;On 15/04/11 01:40, Markus Mohrhard wrote:
    <blockquote
      cite="mid:BANLkTindf-H0hq00p+24AjTn0iEdpwrDFA@mail.gmail.com"
      type="cite">
      <div>And again with the patches.</div>
      <div><br>
      </div>
      <div class="gmail_quote">2011/4/15 Markus Mohrhard <span
          dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:markus.mohrhard@googlemail.com">markus.mohrhard@googlemail.com</a>&gt;</span><br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div>Hi Noel,<br>
          </div>
          <div><br>
          </div>
          <div>here is the patch without the conversion from
            XSpreadsheet to XWorksheet.</div>
          <div><br>
          </div>
          <div>I found some nice Code in ScVbaWorkbook::getActiveSheet()
            where nearly the same thing was done. But the following
            attempt didn't work, and created always an error message in
            getDocUnoModule()</div>
          <div><br>
          </div>
          <div> uno::Reference&lt;frame::XModel&gt; xNewModel(
            getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW );<br>
            ScDocShell* pShell = excel::getDocShell( xNewModel );<br>
            if( !pShell )<br>
            throw uno::RuntimeException();<br>
            ScDocument* pDoc = pShell-&gt;GetDocument();<br>
            String aCodeName;<br>
            pDoc-&gt;GetCodeName((SCTAB)0 ,aCodeName);<br>
            return uno::Reference&lt; excel::XWorksheet &gt;(
            getUnoDocModule( aCodeName, pShell ), uno::UNO_QUERY_THROW
            );<br>
          </div>
          <div><br>
          </div>
          <div>With a debugger you see that pShell points to the correct
            ScDocShell and aCodeName points to the CodeName of the
            ScTable but it still won't work.</div>
          <div><br>
          </div>
          <div>Perhabs you know why my idea won't work. Nearly the same
            code works fine with&nbsp;ScVbaWorkbook::getActiveSheet()</div>
        </blockquote>
      </div>
    </blockquote>
    ok, first using getCurrentExcelDoc is not really recommended ( when
    we actually know the target document ) 'active' is a little
    arbitrary and I am not sure in this case whether there is a timing
    issue between the document being created and being recognised as
    'active'. But regardless of that the getUnoDocModule is not going to
    succeed as the (new) document is not vba enabled. Some post
    processing of the document is needed to ensure that works, like I
    said.. if you are interested in hacking on that as a separate issue
    then I can give you pointers how that is done ( actually it is
    already done in ScVbaWorkbooks ( see setUpDocumentModules method ) )
    but that method would need to be generally available in
    excelvbahelper I think<br>
    <blockquote
      cite="mid:BANLkTindf-H0hq00p+24AjTn0iEdpwrDFA@mail.gmail.com"
      type="cite">
      <div class="gmail_quote">
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div><br>
          </div>
          <div>Patch is under LGPLv3+/MPL.</div>
          <div><br>
          </div>
          <div>Regards,</div>
          <div>Markus</div>
          <div><br>
          </div>
          <div class="h5">P.S. Even some really strange ways of using
            the setUpDocumentModules(const uno::Reference&lt;
            sheet::XSpreadsheetDocument &gt;) of vbaworkbooks.cxx
            produces an error. But this seems a good way to solve the
            problem. If you can give me any hints why this won't work I
            will try again on the conversion<br>
          </div>
        </blockquote>
      </div>
    </blockquote>
    hmm not without looking more closely at that ( which I will try to
    do later ) it imo should work<br>
    <br>
    now on to the patch :-)<br>
    <br>
    in vbaworksheet.cxx<br>
    <br>
    +&nbsp;&nbsp;&nbsp; //#TODO #FIXME<br>
    +&nbsp;&nbsp;&nbsp; //return the new XWorksheet<br>
    +&nbsp;&nbsp;&nbsp; return;<br>
    <br>
    I meant to not return NULL but pass NULL as the parent of the
    Worksheet ;-)&nbsp; fixed that ( of course we need to look into the
    problems mentioned above to see what we can do to get the correct
    parent )<br>
    <br>
    A few more changes were needed to vbaworksheets, mostly these
    changes were required because on testing it became clear that things
    weren't working exactly as expected and there are a few bugs
    e.g.calling<br>
    &nbsp;&nbsp; Worksheets.Copy() <br>
    creates a copy of the sheets in a new workbook but there are in
    reverse order<br>
    <br>
    Similarly when calling<br>
    &nbsp;&nbsp; Worksheets.Copy before:= Worksheets(2)<br>
    the sheets are also copied in reverse order. I fixed those 2
    problems and additionally reworked the method and removed one of the
    loops in the ScVbaWorksheets::Copy method<br>
    <br>
    thanks again for this useful patch, look forward to you next
    contribution<br>
    <br>
    Noel<br>
    <br>
    <br>
    <br>
  </body>
</html>