Several examples of Macro codes in python for calc (just launch the web translator and enjoy):
Part1:
Macroの杜(Python編 / Calc)
Content:
Cell operation
[Basic]
CCB-) [Calc] Enter a value in Cell 1 (character string) CCB-) [Calc] Enter a value in Cell 2 (number / formula) CCB-) [Calc] Enter a value in Cell 3 (number / formula / String) [A1 format address] CCB-) [Calc] Get value from Cell
[Insert ・ Delete.Copy]
CCI-) [Calc] Add Cell (1) [Move existing data downward] [uno.createUnoStruct / insertCells / com.sun.star.sheet.CellInsertMode.DOWN] CCI-) [Calc] Add Cell ( CCI-) [Calc] Add Cell ( CCI-) [Calc] Add Cell 2) [Existing data moves to the right] [com.sun.star.sheet.CellInsertMode.RIGHT] CCI-) [Calc] Add Cell (3) [Moves the entire row downward] [com.sun. star.sheet.CellInsertMode.ROWS] CCI-) [Calc] Add Cell (4) [Move entire column to the right] [com.sun.star.sheet.CellInsertMode.COLUMNS] CCI-) [Calc] Cell Add (5) [Move right / bottom / entire row / column] [ [.uno: InsertCell] CCI-) [Calc] Delete Cell (1) [Move existing data upward] [removeRange / com. sun.star.sheet.CellDeleteMode.UP] CCI-) [Calc] Delete Cell (2) [Move existing data to the left] [com.sun.star.sheet.CellDeleteMode.LEFT] CCI-) [Calc] Delete Cell (3) [Whole row upward Move] [com.sun.star.sheet.CellDeleteMode.ROWS] CCI-) [Calc] Delete Cell (4) [Move entire column to the left] [com.sun.star.sheet.CellDeleteMode.COLUMNS] CCI -) [Calc] Delete Cell (move left / top / entire row / entire column) [.uno: DeleteCell] CCI-) [Calc] Cell COPY [copyRange] CCI-) [Calc] Cell COPY2 [getData ] () / setData] CCI-) [Calc] COPY3 in Cell range [getDataArray / setDataArray] CCI-) [Calc] Select and paste format[.uno: InsertContents] CCI-) [Calc] Copy to another Document [.getComponents / os.path.basename (.Location ()) / .createEnumeration () / .hasMoreElements () / .nextElement () / .hasLocation ()]
[Property (Formatting Cell)]
CCProp-) [Calc] Unformat directly set [.uno: ResetAttributes]
[Format]
CCPF-) [Calc] Get Cell Display Format Key No. [NumberFormats / queryKey] CCPF-) [Calc] Set Cell Numerical Display Format 1 [NumberFormats / queryKey] CCPF-) [Calc] Cell Numerical Display Format Setting 2 [NumberFormat] CCPF-) [Calc] Cell Set the display format of numbers 3 [.uno: NumberFormatValue] CCPF-) [Calc] Content Type of Cell [com.sun.star.CellContentType] CCPF-) [Calc] User Defined Attributes [com.sun.star.table.CellProperties Service] CCPF-) [Calc] Unique Format Range [getCellFormatRanges () / getRangeAddress () / getRangeAddressesAsString ()]
[Font]
CCPFt-) [Calc] Line breaks according to Cell width (1) [.IsTextWrapped] CCPFt-) [Calc] Line breaks according to Cell width (2) [.uno: WrapText] CCPFt-) [Calc] Character-related Property List [from com.sun.star.awt.FontSlant import (NONE, ITALIC, REVERSE_ITALIC, OBLIQUE,) / .CharFontName / .CharFontNameAsian / .CharPosture / CharPostureAsian / .CharPostureAsian / .CharHeight / .CharHeightAsian / .createTextCursor () /. setPropertyValue ('CharContoured',) / .setPropertyValue ('CharCrossedOut,) / .setPropertyValue ('CharEmphasis',) / .setPropertyValue ('CharUnderlineColor',) / .setPropertyValue ('CharUnderline',) / .setPropertyValue ('CharRelief',) ) / .SetPropertyValue ('CharShadowed', )] CCPFt-) [Calc]Make the right character of the character string a subscript character [CharEscapement / CharEscapementHeight] CCPFt-) [Calc] Cell background color setting (1) [.CellBackColor] CCPFt-) [Calc] Cell background color setting (2) [ .uno: BackgroundPattern / BackgroundPattern.BackColor] CCPFt-) [Calc] Character Angle (1) [.RotateAngle] CCPFt-) [Calc] Character Color / Character Size / Character Weight Setting [CharColor / CharHight / CharWeight] CCPFt- ) [Calc] Vertical writing [.uno: TextdirectionTopToBottom]
[Font Effet] [Refer to “Font / Character-related Property List”]
CCFEt-) [Calc] Various UnderLine settings [.CharUnderline / from com.sun.star.awt.FontUnderline import (NONE, SINGLE, DOUBLE, DOTTED, DONTKNOW, DASH, LONGDASH, DASHDOT, DASHDOTDOT, SMALLWAVE, WAVE, DOUBLEWAVE, BOLD , BOLDDOTTED, BOLDDASH, BOLDLONGDASH, BOLDDASHDOT, BOLDDASHDOTDOT, BOLDWAVE,)] CCFEt-) [Calc] Underline color / Color of Underline [.CharUnderlineColor / .CharUnderlineHasColor] CCFEt-) [Calc] Shadowed characters (1) [.CharShadowed] CCFEt-) [Calc] Shadowed characters (2) [.uno: Shadowed] CCFEt-) [Calc] Various strikethroughs (1) [.CharHeight / .CharHeightAsian / .CharStrikeout] CCFEt-) [Calc]Various strikeouts (2) [.uno: Strikeout / Strikeout.Kind] CCFEt-) [Calc] Various OverLine [.setPropertyValue ('CharEmphasis',)] CCFEt-) [Calc] Embossed / embossed characters (1) [.setPropertyValue ( 'CharRelief',)] CCFEt-) [Calc] embossed / embossed characters (2) [.Uno: CharacterRelief] CCFEt-) [Calc] hollowed character (1) [.CharContoured] CCFEt-) [Calc] hollowed Characters (2) [.uno: OutlineFont] CCFEt-) [Calc] []
[Position / Size]
CCPoSz-) [Calc] Position settings in Cell (1) [Vertical] [.VertJustify / from com.sun.star.table.CellVertJustify import (STANDARD, TOP, CENTER, BOTTOM)] CCPoSz-) [Calc] Cell Position settings in (2) [Horizontal] [.HoriJustify / from com.sun.star.table.CellHoriJustify import (STANDARD, LEFT, CENTER, RIGHT, BLOCK, REPEAT)] CCPoSz-) [Calc] Position in Cell Settings (3) [ Vertical / Horizontal] [.uno: VerticalJustification / .uno: HorizontalJustification] CCPoSz-) [Calc] []
[Color]
CCCo-) [Calc] Character Color ⇔ Character color [.CharColor] CCCo-) [Calc ] Make only the amount part (right part) of the character string red ⇔ Color of current symbol [createTextCursor () / setPropertyValue (,) / CharColor]
[Clear]
CCClr-) [Calc] Claer contents (1) [from com.sun.star.sheet.CellFlags import (VALUE, DATETIME, STRING, ANNOTATION, FORMULA, HARDATTR, STYLES, OBJECTS, EDITATTR, FORMATTED,) / .clearContents] CCClr -) [Calc] Column Selection (1) ⇔ Select Columns (1) [.select / getColumns ()]
[Selection]
CCClr-) [Calc] Cell Selection (1) ⇔ Select Cells (1) [.select] CCClr-) [Calc] Column Selection (1) ⇔ Select Columns (1) [.select / getColumns ()]
[Address]
CCAd-) [Calc] Get Current Cell Address (1) [com.sun.star.sheet.SheetCellRange / .getRangeAddress ()] CCAd-) [Calc] Get Last Row No. (1) CCAd-) [Calc ] Get last line number (2) [.uno: GoUpToStartOfData]
Part 2 - Content:
Macroの杜(Python編 / Calc)
Cell operation (2)
[Column・Row(row・column)]
CCR-) Insert [Calc] Row (1) [] CCR-) Insert [Calc] Column (1) [] CCR-) Delete [Calc] Row (1) [] CCR-) In [Calc] Column Delete (1) [] CCR-) [Calc] Get Row Height & Column Width [] CCR-) [Calc] Set Row Height & Column Width (1) [] CCR-) [Calc] Get Row Height & Column Width & Optimize column width (1) [] CCR-) [Calc] Show / hide rows / columns (1) [] CCR-) [Calc] Show / hide multiple rows / columns (1) []
[ Hyper Link ]
CHy-) [Calc]Hyper Link[ com.sun.star.text.textfield.URL / .URL / .Representation / .TargetFrame/ .insertTextContent() ]
[ Array ]
CCD-) [Calc] Get all the data in the specified range [.getDataArray ()] CCD-) [Calc] []
[Sheet]
CS-) [Calc] Get Sheet Name CS-) [Calc] Change Sheet Name CS-) [Calc] Get all Sheet names CS-) [Calc] Check if there is a Sheet name
[File]
CF-) [Calc] New Calc file to start CF-) [Calc] Specify Calc file to start CF-) [Calc] Specify Calc file to save (save in 上书き)
[Graph Chart creation]
CGhCt-) [Calc]各種Graph作成(0)[ .getCharts() / .hasByName() / .RemoveByName() / addNewByName(,,,,) / .embeddedObject ] CGhCt-) [Calc]各種Graph作成(3)[ .getFirstDiagram() / .getChartTypeManager() / com.sun.star.chart2.template.ScatterLineSymbol / .changeDiagram() ] CGhCt-) [Calc]Chart AreaのProperties[ .getArea() / .FillStyle / .FillBackground / .FillColor / .FillTransparence / .LineStyle / .LineWidth / .LineColor / .LineTransparence / .getDiagram() / getWall() ] CGhCt-) [Calc]Data SeriesのProperties[ .getFirstDiagram() / .getCoordinateSystems() / .getChartTypes() / .getDataSeries() / .Color ] CGhCt-) [Calc][ ]
[Printing operation]
CP-) [Calc] Insert / Release Page Break (1) [IsStartOfNewPage] CP-) [Calc] Insert / Cancel Page Break (2) [IsStartOfNewPage] CP-) [Calc] Cancel All Page Breaks [] CP -) [Calc] Set / Get print range [setPrintAreas () / getPrintAreas () / hasUnoInterfaces ()] CP-) [Calc] Define / change / add / delete print range [.uno: DefinePrintArea / .uno: ChangePrintArea / .uno: AddPrintArea / .uno: DeletePrintArea] CP-) [Calc] Get PageStyle (margin, header, footer) [] CP-) [Calc] []