Guest User

Untitled

a guest
Feb 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. Sub CellAddress
  2.  
  3. Dim oConv
  4. Dim oCell
  5. Dim oDoc
  6.  
  7. Dim oCellAddr As New com.sun.star.table.CellAddress
  8.  
  9. oDoc=ThisComponent
  10. oConv = oDoc.createInstance("com.sun.star.table.CellAddressConversion")
  11.  
  12.  
  13. oCell = ThisComponent.Sheets(0).getCellByPosition(2, 4)
  14.  
  15. oConv.Address = oCell.getCellAddress()
  16.  
  17. Print oConv.UserInterfaceRepresentation
  18. print oConv.PersistentRepresentation
  19.  
  20. oCellAddr= oCell.getCellAddress()
  21.  
  22. print oCellAddr.Sheet
  23. print oCellAddr.Column
  24. print oCellAddr.Row
  25.  
  26.  
  27. End Sub
  28.  
  29. Rem ---------------------------------------------
  30.  
  31. Sub CellType
  32. Dim CellType as String
  33. dim oCell
  34.  
  35.  
  36. oCell = ThisComponent.Sheets(0).getCellByPosition(0, 0) 'Cell A1
  37.  
  38. Select Case oCell.getType()
  39. Case com.sun.star.table.CellContentType.EMPTY
  40. CellType = "Empty"
  41. Case com.sun.star.table.CellContentType.VALUE
  42. CellType = "Value"
  43. Case com.sun.star.table.CellContentType.TEXT
  44. CellType = "Text"
  45. Case com.sun.star.table.CellContentType.FORMULA
  46. CellType = "Formula"
  47. Case Else
  48. CellType = "Unknown"
  49. End Select
  50.  
  51. msgbox CellType
  52. End sub
  53.  
  54. Rem ---------------------------------------------
  55.  
  56. Function GetCellType(oCell) As String
  57. Select Case oCell.getType()
  58. Case com.sun.star.table.CellContentType.EMPTY
  59. GetCellType = "Empty"
  60. Case com.sun.star.table.CellContentType.VALUE
  61. GetCellType = "Value"
  62. Case com.sun.star.table.CellContentType.TEXT
  63. GetCellType = "Text"
  64. Case com.sun.star.table.CellContentType.FORMULA
  65. GetCellType = "Formula"
  66. Case Else
  67. GetCellType = "Unknown"
  68. End Select
  69. End Function
  70.  
  71. Rem ---------------------------------------------
  72.  
  73.  
  74. Function SimpleCellInfo(oCell) As String
  75. SimpleCellInfo = oCell.AbsoluteName & " has type " &_
  76. GetCellType(oCell) & " String(" & oCell.getString() & ") Value(" &_
  77. oCell.getValue() & ") Formula(" & oCell.getFormula() & ")"
  78. End Function
  79.  
  80.  
  81. Rem ---------------------------------------------
  82.  
  83.  
  84. Sub Ex1
  85.  
  86. Dim oCell
  87. Dim s As String
  88. Dim oDoc
  89.  
  90. oDoc = ThisComponent
  91.  
  92. oCell = oDoc.Sheets(0).getCellByPosition(0, 0)
  93.  
  94. oCell.setString("Andy")
  95.  
  96. s = SimpleCellInfo(oCell) & CHR$(10)
  97. MsgBox s, 0, "Cell Values And Types"
  98.  
  99. End Sub
  100.  
  101. Rem ---------------------------------------------
  102.  
  103. Sub Ex2
  104.  
  105. Dim oCell
  106. Dim oDoc
  107.  
  108. oDoc = ThisComponent
  109. oCell = oDoc.Sheets(0).getCellByPosition(1, 0)
  110.  
  111. s = SimpleCellInfo(oCell) & CHR$(10)
  112. MsgBox s, 0, "Cell Values And Types"
  113.  
  114. end sub
  115.  
  116. Rem ---------------------------------------------
  117.  
  118. Sub Ex3
  119. Dim oCell
  120. Dim s As String
  121. Dim oDoc
  122. oDoc = ThisComponent
  123.  
  124. oCell = oDoc.Sheets(0).getCellByPosition(1, 0)
  125. oCell.setValue(23.2)
  126.  
  127. s = s & SimpleCellInfo(oCell) & CHR$(10)
  128. MsgBox s, 0, "Cell Values And Types"
  129.  
  130. End Sub
  131.  
  132. Rem ---------------------------------------------
  133.  
  134. Sub Ex4
  135. Dim oCell
  136. Dim s As String
  137. Dim oDoc
  138. oDoc = ThisComponent
  139.  
  140. oCell = oDoc.Sheets(0).getCellByPosition(2, 0)
  141. oCell.setString("4")
  142.  
  143. s = s & SimpleCellInfo(oCell) & CHR$(10)
  144. MsgBox s, 0, "Cell Values And Types"
  145. End Sub
  146.  
  147. Rem ---------------------------------------------
  148.  
  149. Sub Ex5
  150. Dim oCell
  151. Dim s As String
  152. Dim oDoc
  153. oDoc = ThisComponent
  154.  
  155. oCell = oDoc.Sheets(0).getCellByPosition(3, 0)
  156. oCell.setFormula("=B1")
  157.  
  158. s = s & SimpleCellInfo(oCell) & CHR$(10)
  159. MsgBox s, 0, "Cell Values And Types"
  160.  
  161. End Sub
  162.  
  163. Rem ---------------------------------------------
  164.  
  165. Sub Ex6
  166. Dim oCell
  167. Dim s As String
  168. Dim oDoc
  169. oDoc = ThisComponent
  170.  
  171. oCell = oDoc.Sheets(0).getCellByPosition(3, 0)
  172. oCell.setFormula("")
  173.  
  174. s = s & SimpleCellInfo(oCell) & CHR$(10)
  175. MsgBox s, 0, "Cell Values And Types"
  176.  
  177. End Sub
  178.  
  179. Rem ---------------------------------------------
  180.  
  181. Sub Ex7
  182. Dim oCell
  183. Dim s As String
  184. Dim oDoc
  185. oDoc = ThisComponent
  186.  
  187. oCell = oDoc.Sheets(0).getCellByPosition(0,1)
  188. oCell.setFormula("=A1+A2+A3")
  189.  
  190. s = s & SimpleCellInfo(oCell) & CHR$(10)
  191. MsgBox s, 0, "Cell Values And Types"
  192.  
  193. End Sub
  194.  
  195. Rem ---------------------------------------------
  196.  
  197. Sub Ex8
  198. Dim oCell
  199. Dim s As String
  200. Dim oDoc
  201. Dim oSheet
  202.  
  203. oDoc = ThisComponent
  204. oSheet=oDoc.Sheets(0)
  205. oCell = oDoc.Sheets(0).getCellByPosition(0,1)
  206.  
  207. oCell.setValue(oSHeet.getCellByPosition(0,0).getValue()+_
  208. oSheet.getCellByPosition(1,0).getValue()+_
  209. oSheet.getCellByPosition(2,0).getValue())
  210.  
  211.  
  212. s = s & SimpleCellInfo(oCell) & CHR$(10)
  213. MsgBox s, 0, "Cell Values And Types"
  214.  
  215. End Sub
Add Comment
Please, Sign In to add comment