[Solved] How to disable screen update, change calculate mode

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
ikw_chen
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

[Solved] How to disable screen update, change calculate mode

Post by ikw_chen »

Hi All,

When fill data to Calc cells use UNO API (Java), it's take a lot time to re-calculate all formula related to the updated cell.

Is there any way temporary disable the screen update & the change the calculate mode from automatic to manual like MS Excel does.

Code: Select all

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
...
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


Code: Select all

XComponent xSpreadsheetComponent = xCompLoader.loadComponentFromURL(sLoadUrl, "_default", 0, loadProps);
XSpreadsheetDocument xDocument = (XSpreadsheetDocument)UnoRuntime.queryInterface(XSpreadsheetDocument.class,xSpreadsheetComponent);
		
XSpreadsheets xSheets = xDocument.getSheets();
Object oSheet = xSheets.getByName(sheet_Estimation);
XSpreadsheet xSheet = (XSpreadsheet)UnoRuntime.queryInterface(XSpreadsheet.class, oSheet);
			
rgColName = xSheet.getCellRangeByName("colName");

rgColName .getCellByPosition(x, y).setFormula("abc"); 

...
Thanks for advice!
Last edited by TheGurkha on Sun Jul 10, 2011 5:47 pm, edited 2 times in total.
Reason: Tagged Solved, TheGurkha.
Openoffice 3.3 on WinXP
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How to disable screen update , change calculate mode on

Post by Zizi64 »

Hi,

You can switch on/off the Autocalculation Option in Menu:
Tools - Cell Content - AutoCalculate

I have recorded this code by Macrorecorder:

Code: Select all

rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "AutomaticCalculation"
args1(0).Value = false

dispatcher.executeDispatch(document, ".uno:AutomaticCalculation", "", 0, args1())
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to disable screen update , change calculate mode on

Post by Villeroy »

Found Calc equivalent to Excel's ScreenUpdating = False

Code: Select all

import com.sun.star.sheet.XCalculatable;
import com.sun.star.uno.UnoRuntime;

static public void snippet(Object oInitialTarget)
{
	XCalculatable xCalculatable = UnoRuntime.queryInterface(
		XCalculatable.class, oInitialTarget);
	xCalculatable.enableAutomaticCalculation(false);
	
}
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: How to disable screen update , change calculate mode on

Post by B Marcelly »

Hi,
Freezing screen is done with method lockControllers() of the document's Model.
Freezing recalculations is done with method addActionLock() of the document.
With Basic it's simple:

Code: Select all

myDoc = ThisComponent
myDoc.lockControllers()
myDoc.addActionLock()
' --- modify your cells here ---
myDoc.removeActionLock()
myDoc.unlockControllers()
In Java you have to get the interfaces.
Lock/unlock and add/remove must work in pairs.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
ikw_chen
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

Re: How to disable screen update , change calculate mode on

Post by ikw_chen »

Thanks all for your help :).

I tried with code propose by Villeroy, the performance increased a bit (by change the XcalculateTable to Manual). But when I fill data to cell, it's still update on screen. I'm still looking for the method to freezing screen (in Java) as mentioned by B Marcelly

Freezing screen is done with method lockControllers() of the document's Model.
Freezing recalculations is done with method addActionLock() of the document.

Code: Select all

   XCalculatable xCalculatable = UnoRuntime.queryInterface(
      XCalculatable.class, oInitialTarget);
   xCalculatable.enableAutomaticCalculation(false);
Regards,
Openoffice 3.3 on WinXP
ikw_chen
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

Re: How to disable screen update , change calculate mode on

Post by ikw_chen »

Combine method propose by B Marcelly. It works well.

Thanks all so much.

Regards,
Openoffice 3.3 on WinXP
Post Reply