[Libreoffice] How to create get an XWorksheet from a XSpreadsheet?
markus.mohrhard at googlemail.com
Thu Apr 14 17:39:22 PDT 2011
here is the patch without the conversion from XSpreadsheet to XWorksheet.
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()
uno::Reference<frame::XModel> xNewModel( getCurrentExcelDoc( mxContext ),
ScDocShell* pShell = excel::getDocShell( xNewModel );
if( !pShell )
ScDocument* pDoc = pShell->GetDocument();
return uno::Reference< excel::XWorksheet >( getUnoDocModule( aCodeName,
pShell ), uno::UNO_QUERY_THROW );
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.
Perhabs you know why my idea won't work. Nearly the same code works fine
Patch is under LGPLv3+/MPL.
P.S. Even some really strange ways of using the setUpDocumentModules(const
uno::Reference< sheet::XSpreadsheetDocument >) 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
2011/4/14 Noel Power <nopower at novell.com>
> Hi Markus
> On 14/04/11 00:49, Markus Mohrhard wrote:
>> I have reworked most of the Code but have now the problem that I have an
>> instance of XSpreadsheet but need the corresponding XWorksheet object.
>> I found one of these conversions at ScVbaWorksheet::getSheetAtOffset but
>> it needs to call getParent, which will not work in my case because it is for
>> the new method createSheetCopyInNewDoc. Do you know any way to resolve this
> aha very good!! I didn't think of that, nice catch. Ok, here is what I
> propose, I think you have suffered enough with this so-called easy hack,
> just pass null as the parent and lets get the patch reviewed and in. Please
> do put a #TODO #FIXME in the code where the parent is (NOT) created.
> The parent should be a Workbook object, problem here is that when you
> create a new document, just creating a workbook object isn't enough as those
> parents are by a weakreference and the workbook object you would create
> would only be temporary.
> If the new document was created correctly ( e.g. in vba mode ) then we
> could use the getUnoDocModule() to access the correct Workbook instance and
> pass that instead. I think we need to tweak the existing code more to do
> that ( some stuff like this is already done in ScWorkbooks::Add ). if you
> are interested I'd give you some advice/hints on how that should be done and
> you could do that as a separate hack ( let me know if you are interested in
> doing that ) Otherwise just open a bug for that part and assign it to me and
> I will either fix it or create another easy hack from that.
> thanks for you continued efforts
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the LibreOffice