rubyexcel 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/rubyexcel/excel_tools.rb +17 -10
  2. metadata +2 -2
@@ -1,4 +1,5 @@
1
- require 'win32ole'
1
+ require 'win32ole' #Interface with Excel
2
+ require 'win32/registry' #Find Documents / My Documents for default directory
2
3
 
3
4
  module ExcelConstants; end
4
5
 
@@ -24,14 +25,14 @@ module RubyExcel
24
25
  sheet
25
26
  end
26
27
 
27
- def get_excel
28
+ def get_excel( invisible = false )
28
29
  excel = WIN32OLE::connect( 'excel.application' ) rescue WIN32OLE::new( 'excel.application' )
29
- excel.visible = true
30
+ excel.visible = true unless invisible
30
31
  excel
31
32
  end
32
33
 
33
- def get_workbook( excel=nil )
34
- excel ||= get_excel
34
+ def get_workbook( excel=nil, invisible = false )
35
+ excel ||= get_excel( invisible )
35
36
  wb = excel.workbooks.add
36
37
  ( ( wb.sheets.count.to_i ) - 1 ).times { |time| wb.sheets(2).delete }
37
38
  wb
@@ -39,22 +40,28 @@ module RubyExcel
39
40
 
40
41
  def make_sheet_pretty( sheet )
41
42
  c = sheet.cells
43
+ c.rowheight = 15
42
44
  c.entireColumn.autoFit
43
45
  c.horizontalAlignment = -4108
44
46
  c.verticalAlignment = -4108
45
47
  sheet
46
48
  end
47
49
 
48
- def save_excel( filename = 'Output.xlsx' )
49
- filename = Dir.pwd.gsub('/','\\') + '\\' + filename unless filename.include?('\\')
50
- wb = to_excel
50
+ def save_excel( filename = 'Output', invisible = false )
51
+ filename = filename.gsub('/','\\')
52
+ unless filename.include?('\\')
53
+ keypath = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders'
54
+ documents = Win32::Registry::HKEY_CURRENT_USER.open(keypath)['Personal'] rescue Dir.pwd.gsub('/','\\')
55
+ filename = documents + '\\' + filename
56
+ end
57
+ wb = to_excel( invisible )
51
58
  wb.saveas filename
52
59
  wb
53
60
  end
54
61
 
55
- def to_excel
62
+ def to_excel( invisible = false )
56
63
  self.sheets.count == self.sheets.map(&:name).uniq.length or fail NoMethodError, 'Duplicate sheet name'
57
- wb = get_workbook
64
+ wb = get_workbook( nil, invisible )
58
65
  wb.parent.displayAlerts = false
59
66
  first_time = true
60
67
  self.each do |s|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyexcel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-17 00:00:00.000000000 Z
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A tabular data structure, mixing Ruby with some of Excel's API style.
15
15
  email: VirtuosoJoel@gmail.com