rods 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +56 -3
- data/Rakefile +1 -1
- data/lib/rods.rb +132 -3
- data/rods.gemspec +2 -2
- metadata +4 -4
data/README
CHANGED
@@ -14,17 +14,23 @@
|
|
14
14
|
Licensed under the same terms as Ruby. No warranty is provided.
|
15
15
|
|
16
16
|
= Changelog
|
17
|
+
* 0.7.0
|
18
|
+
* added new function
|
19
|
+
* getCellsAndIndicesFor(expression)
|
20
|
+
This function returns all cells and their indices for which
|
21
|
+
the external representation matches the given expression.
|
22
|
+
cf. Example 0.7.0 below
|
17
23
|
* 0.6.2
|
18
24
|
* added style-attributes
|
19
25
|
* text-underline-style
|
20
26
|
* text-underline-width
|
21
27
|
* text-underline-color
|
22
|
-
cf. Example 0.6.2
|
28
|
+
cf. Example 0.6.2 below
|
23
29
|
* 0.6.1
|
24
30
|
* added new functions
|
25
31
|
* insertTableBefore()
|
26
32
|
* insertTableAfter()
|
27
|
-
cf. Example 0.6.1
|
33
|
+
cf. Example 0.6.1 below
|
28
34
|
* 0.6.0
|
29
35
|
* changed interface from
|
30
36
|
* getNextRow, getPreviousRow, getNextCell, getPreviousCell to
|
@@ -316,13 +322,60 @@
|
|
316
322
|
"style:text-underline-width" => "auto"})
|
317
323
|
cell=mySheet.writeGetCell(4,4,"string","Underline_Default_with_Black")
|
318
324
|
#----------------------------------------------------------------------
|
319
|
-
# if not specified otherwise,
|
325
|
+
# if not specified otherwise, width and color are set to default
|
320
326
|
# - black
|
321
327
|
# - solid
|
322
328
|
#----------------------------------------------------------------------
|
323
329
|
mySheet.setAttributes(cell,{ "style:text-underline-style" => "solid" })
|
324
330
|
mySheet.saveAs("Test3.ods")
|
325
331
|
puts("done")
|
332
|
+
|
333
|
+
= Example 0.7.0
|
334
|
+
|
335
|
+
#!/usr/bin/ruby
|
336
|
+
# coding: UTF-8
|
337
|
+
#
|
338
|
+
# Author: Dr. Heinz Breinlinger
|
339
|
+
#
|
340
|
+
require 'rubygems'
|
341
|
+
require 'rods'
|
342
|
+
|
343
|
+
mySheet=Rods.new("Konten.ods")
|
344
|
+
# Finds all cells with content 'content' and returns them along with the
|
345
|
+
# indices of row and column as an array of hashes.
|
346
|
+
# [{ :cell => cell,
|
347
|
+
# :row => rowIndex,
|
348
|
+
# :col => colIndex},
|
349
|
+
# { :cell => cell,
|
350
|
+
# :row => rowIndex,
|
351
|
+
# :col => colIndex}]
|
352
|
+
#
|
353
|
+
# Regular expressions for 'content' are alllowd but must be enclosed in
|
354
|
+
# single (not double) quotes !
|
355
|
+
#
|
356
|
+
# In case of no matches at all, an empty array is returned.
|
357
|
+
#
|
358
|
+
# Keep in mind that the content of a cell with a formula is not the formula, but the
|
359
|
+
# current value of the computed result.
|
360
|
+
#
|
361
|
+
# Also consider that you have to search for the external (i.e. visible)
|
362
|
+
# represenation of a cell's content, not it's internal computational value.
|
363
|
+
# For instance, when looking for a currency value of 1525 (that is shown as
|
364
|
+
# '1.525 $'), you'll have to code
|
365
|
+
#
|
366
|
+
# result=mySheet.getCellsAndIndicesFor('1[.,]525')
|
367
|
+
#
|
368
|
+
# The following finds all occurences of a comma- or dot-separated number,
|
369
|
+
# consisting of 1 digit before and 2 digits behind the decimal-separator.
|
370
|
+
#-------------------------------------------------------------------------
|
371
|
+
result=mySheet.getCellsAndIndicesFor('\d{1}[.,]\\d{2}')
|
372
|
+
result.each{ |cellHash|
|
373
|
+
puts("----------------------------------------------")
|
374
|
+
puts("Node: #{cellHash[:cell]}") # Be aware: Prints out whole node ! ;-)
|
375
|
+
puts("Row: #{cellHash[:row]}")
|
376
|
+
puts("Column: #{cellHash[:col]}")
|
377
|
+
}
|
378
|
+
puts("done")
|
326
379
|
|
327
380
|
= Caveat
|
328
381
|
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('rods', '0.
|
5
|
+
Echoe.new('rods', '0.7.0') do |p|
|
6
6
|
p.description = "OpenOffice.org oocalc: Fast automated batch-processing of spreadsheets (*.ods) conforming to Open Document Format v1.1. used by e.g. OpenOffice.org and LibreOffice. Please see screenshot and Rdoc-Documentation at http://ruby.homelinux.com/ruby/rods/. You can contact me at rodsdotrubyatonlinedotde (and drop me a line, if you like it ;-)"
|
7
7
|
p.summary = "Automation of OpenOffice/LibreOffice by batch-processing of spreadsheets conforming to Open Document v1.1"
|
8
8
|
p.url = "http://ruby.homelinux.com/ruby/rods/"
|
data/lib/rods.rb
CHANGED
@@ -2580,7 +2580,136 @@ class Rods
|
|
2580
2580
|
return row.next_sibling
|
2581
2581
|
end
|
2582
2582
|
##########################################################################
|
2583
|
-
#
|
2583
|
+
# Finds all cells with content 'content' and returns them along with the
|
2584
|
+
# indices of row and column as an array of hashes.
|
2585
|
+
# [{ :cell => cell,
|
2586
|
+
# :row => rowIndex,
|
2587
|
+
# :col => colIndex},
|
2588
|
+
# { :cell => cell,
|
2589
|
+
# :row => rowIndex,
|
2590
|
+
# :col => colIndex}]
|
2591
|
+
#
|
2592
|
+
# Regular expressions for 'content' are alllowd but must be enclosed in
|
2593
|
+
# single (not double) quotes !
|
2594
|
+
#
|
2595
|
+
# In case of no matches at all, an empty array is returned.
|
2596
|
+
#
|
2597
|
+
# The following finds all occurences of a comma- or dot-separated number,
|
2598
|
+
# consisting of 1 digit before and 2 digits behind the decimal-separator.
|
2599
|
+
#
|
2600
|
+
# myArray=mySheet.getCellsAndIndicesFor('\d{1}[.,]\d{2}')
|
2601
|
+
#
|
2602
|
+
# Keep in mind that the content of a call with a formula is not the formula, but the
|
2603
|
+
# current value of the computed result.
|
2604
|
+
#
|
2605
|
+
# Also consider that you have to search for the external (i.e. visible)
|
2606
|
+
# represenation of a cell's content, not it's internal computational value.
|
2607
|
+
# For instance, when looking for a currency value of 1525 (that is shown as
|
2608
|
+
# '1.525 €', you'll have to code
|
2609
|
+
#
|
2610
|
+
# result=mySheet.getCellsAndIndicesFor('1[.,]525')
|
2611
|
+
# result.each{ |cellHash|
|
2612
|
+
# puts("Found #{cellHash[:cell] on #{cellHash[:row] - #{cellHash[:col]")
|
2613
|
+
# }
|
2614
|
+
#-------------------------------------------------------------------------
|
2615
|
+
def getCellsAndIndicesFor(content)
|
2616
|
+
die("getCellsAndIndicesFor: 'content' is not of typ String") unless (content.class.to_s == "String")
|
2617
|
+
result=Array.new()
|
2618
|
+
i=0
|
2619
|
+
tell("getCellsAndIndicesFor: Searching for cells with content '#{content}'")
|
2620
|
+
#----------------------------------------------------------------
|
2621
|
+
# Alle Text-Nodes suchen
|
2622
|
+
#----------------------------------------------------------------
|
2623
|
+
@spreadSheet.elements.each("//table:table-cell/text:p"){ |textNode|
|
2624
|
+
text=textNode.text
|
2625
|
+
#---------------------------------------------------------
|
2626
|
+
# Zelle gefunden ?
|
2627
|
+
#
|
2628
|
+
# 'content' darf regulaerer Ausdruck sein, muss dann jedoch
|
2629
|
+
# in einfachen Hochkommata uebergeben werden
|
2630
|
+
#---------------------------------------------------------
|
2631
|
+
if(text && (text.match(/#{content}/)))
|
2632
|
+
result[i]=Hash.new()
|
2633
|
+
tell("getCellsAndIndicesFor: '#{content}' matched '#{text}'")
|
2634
|
+
#-----------------------------------------------------
|
2635
|
+
# Zelle und Zellenindex ermitteln
|
2636
|
+
#-----------------------------------------------------
|
2637
|
+
cell=textNode.elements["ancestor::table:table-cell"]
|
2638
|
+
unless (cell)
|
2639
|
+
die("getCellsAndIndicesFor: internal error: Could not extract parent-cell of textNode with #{content}")
|
2640
|
+
end
|
2641
|
+
colIndex=getIndexOfElement(cell)
|
2642
|
+
#-----------------------------------------------------
|
2643
|
+
# Zeile und Zeilenindex ermitteln
|
2644
|
+
#-----------------------------------------------------
|
2645
|
+
row=textNode.elements["ancestor::table:table-row"]
|
2646
|
+
unless (row)
|
2647
|
+
die("getCellsAndIndicesFor: internal error: Could not extract parent-row of textNode with #{content}")
|
2648
|
+
end
|
2649
|
+
rowIndex=getIndexOfElement(row)
|
2650
|
+
result[i][:cell]=cell
|
2651
|
+
result[i][:row]=rowIndex
|
2652
|
+
result[i][:col]=colIndex
|
2653
|
+
tell("getCellsAndIndicesFor: Indices #{rowIndex} #{colIndex}")
|
2654
|
+
i+=1
|
2655
|
+
end
|
2656
|
+
}
|
2657
|
+
return result
|
2658
|
+
end
|
2659
|
+
##########################################################################
|
2660
|
+
# internal: Calculates index (in the sense of spreadsheet, NOT XML) of
|
2661
|
+
# given element (row or cell as REXML::Element) within the corresponding parent-element
|
2662
|
+
# (table or row)
|
2663
|
+
#
|
2664
|
+
# index=mySheet.getIndexOfElement(row) # -> Line-number within table
|
2665
|
+
#-------------------------------------------------------------------------
|
2666
|
+
def getIndexOfElement(node)
|
2667
|
+
die("getIndexOfElements: passed node '#{node}' is not a REXML::Element") unless (node.class.to_s == "REXML::Element")
|
2668
|
+
index=0
|
2669
|
+
#--------------------------------------------------------------
|
2670
|
+
# Typabhaengige Vorbelegungen
|
2671
|
+
#--------------------------------------------------------------
|
2672
|
+
if(node.elements["self::table:table-cell"])
|
2673
|
+
kindOfSelf="table:table-cell"
|
2674
|
+
kindOfParent="table:table-row"
|
2675
|
+
kindOfRepetition="table:number-columns-repeated"
|
2676
|
+
elsif(node.elements["self::table:table-row"])
|
2677
|
+
kindOfSelf="table:table-row"
|
2678
|
+
kindOfParent="table:table"
|
2679
|
+
kindOfRepetition="table:number-rows-repeated"
|
2680
|
+
else
|
2681
|
+
die("getIndexOfElement: internal error: passed element '#{node}' is neither cell nor row")
|
2682
|
+
end
|
2683
|
+
#--------------------------------------------------------------
|
2684
|
+
# Zugehoeriges Vater-Element ermitteln
|
2685
|
+
#--------------------------------------------------------------
|
2686
|
+
parent=node.elements["ancestor::"+kindOfParent]
|
2687
|
+
unless (parent)
|
2688
|
+
die("getIndexOfElement: internal error: Could not extract parent of #{node}")
|
2689
|
+
end
|
2690
|
+
#--------------------------------------------------------------
|
2691
|
+
# Index des Kind-Elements innerhalb Vater-Element ermitteln
|
2692
|
+
#--------------------------------------------------------------
|
2693
|
+
parent.elements.each(kindOfSelf){ |child|
|
2694
|
+
index+=1
|
2695
|
+
#-----------------------------------------------
|
2696
|
+
# Bei Treffer -> Ruecksprung mit aktuellem Index
|
2697
|
+
#-----------------------------------------------
|
2698
|
+
if(child == node)
|
2699
|
+
return index
|
2700
|
+
#-----------------------------------------------
|
2701
|
+
# Wiederholungen zaehlen
|
2702
|
+
# Cave: Aktuelles Element selbst zaehlt ebenfalls als Wiederholung
|
2703
|
+
# => um 1 dekrementieren
|
2704
|
+
#-----------------------------------------------
|
2705
|
+
elsif(repetition=child.attributes[kindOfRepetition])
|
2706
|
+
index+=repetition.to_i-1
|
2707
|
+
end
|
2708
|
+
}
|
2709
|
+
die("getIndexOfElement: internal error: Could not calculate index of element #{node}")
|
2710
|
+
end
|
2711
|
+
##########################################################################
|
2712
|
+
# internal: Opens zip-file
|
2584
2713
|
#-------------------------------------------------------------------------
|
2585
2714
|
def open(file)
|
2586
2715
|
die("open: file #{file} does not have valid ending '*.ods'") unless (file.match(/\.ods$/))
|
@@ -2600,11 +2729,11 @@ class Rods
|
|
2600
2729
|
:insertTable, :deleteTable, :readCellFromRow, :readCell, :setAttributes, :writeStyleAbbr,
|
2601
2730
|
:setStyle, :printOfficeStyles, :printAutoStyles, :getNextExistentRow, :getPreviousExistentRow,
|
2602
2731
|
:getNextExistentCell, :getPreviousExistentCell, :insertTableAfter, :insertTableBefore,
|
2603
|
-
:writeComment, :save, :saveAs, :initialize, :writeText
|
2732
|
+
:writeComment, :save, :saveAs, :initialize, :writeText, :getCellsAndIndicesFor
|
2604
2733
|
|
2605
2734
|
private :tell, :die, :createCell, :createRow, :getChildByIndex, :createElement, :setRepetition, :initHousekeeping,
|
2606
2735
|
:getTableWidth, :padTable, :padRow, :time2TimeVal, :percent2PercentVal, :date2DateVal,
|
2607
|
-
:finalize, :init, :normalizeText, :getColor, :normStyleHash, :getStyle,
|
2736
|
+
:finalize, :init, :normalizeText, :getColor, :normStyleHash, :getStyle, :getIndexOfElement,
|
2608
2737
|
:getAppropriateStyle, :checkStyleAttributes, :insertStyleAttributes, :cloneNode,
|
2609
2738
|
:writeStyle, :writeStyleXml, :style2Hash, :writeDefaultStyles, :writeXml,
|
2610
2739
|
:internalizeFormula, :getColorPalette, :open, :printStyles, :insertTableBeforeAfter
|
data/rods.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rods}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.7.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Dr. Heinz Breinlinger"]
|
9
|
-
s.date = %q{2011-01-
|
9
|
+
s.date = %q{2011-01-11}
|
10
10
|
s.description = %q{OpenOffice.org oocalc: Fast automated batch-processing of spreadsheets (*.ods) conforming to Open Document Format v1.1. used by e.g. OpenOffice.org and LibreOffice. Please see screenshot and Rdoc-Documentation at http://ruby.homelinux.com/ruby/rods/. You can contact me at rodsdotrubyatonlinedotde (and drop me a line, if you like it ;-)}
|
11
11
|
s.email = %q{rods.ruby@online.de}
|
12
12
|
s.extra_rdoc_files = ["README", "lib/example.rb", "lib/rods.rb"]
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dr. Heinz Breinlinger
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-11 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|