robust_excel_ole 1.11 → 1.12
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.
- checksums.yaml +4 -4
- data/Changelog +11 -0
- data/README.rdoc +20 -8
- data/docs/README_open.rdoc +1 -0
- data/docs/README_ranges.rdoc +5 -11
- data/examples/{introducing_examples/example_introducing.rb → introductory_examples/example_introductory.rb} +10 -2
- data/examples/{introducing_examples → introductory_examples}/example_open.rb +18 -17
- data/examples/{introducing_examples → introductory_examples}/example_range.rb +29 -16
- data/examples/modifying_sheets/example_access_sheets_and_cells.rb +8 -7
- data/examples/modifying_sheets/example_add_names.rb +4 -8
- data/examples/modifying_sheets/example_adding_sheets.rb +7 -6
- data/examples/modifying_sheets/example_concating.rb +2 -2
- data/examples/modifying_sheets/example_copying.rb +3 -3
- data/examples/modifying_sheets/example_expanding.rb +2 -2
- data/examples/modifying_sheets/example_naming.rb +2 -2
- data/examples/modifying_sheets/example_ranges.rb +4 -4
- data/examples/modifying_sheets/example_saving.rb +3 -3
- data/examples/open_save_close/example_control_to_excel.rb +10 -11
- data/examples/open_save_close/example_default_excel.rb +13 -14
- data/examples/open_save_close/example_force_excel.rb +9 -10
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +7 -7
- data/examples/open_save_close/example_if_obstructed_forget.rb +5 -5
- data/examples/open_save_close/example_if_obstructed_save.rb +7 -7
- data/examples/open_save_close/example_if_unsaved_accept.rb +13 -13
- data/examples/open_save_close/example_if_unsaved_forget.rb +9 -10
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +9 -10
- data/examples/open_save_close/example_read_only.rb +6 -6
- data/examples/open_save_close/example_rename_cells.rb +4 -5
- data/examples/open_save_close/example_reuse.rb +6 -6
- data/examples/open_save_close/example_simple.rb +5 -5
- data/examples/open_save_close/example_unobtrusively.rb +4 -4
- data/lib/robust_excel_ole/address.rb +0 -4
- data/lib/robust_excel_ole/bookstore.rb +4 -28
- data/lib/robust_excel_ole/excel.rb +17 -22
- data/lib/robust_excel_ole/general.rb +11 -18
- data/lib/robust_excel_ole/range_owners.rb +17 -27
- data/lib/robust_excel_ole/reo_common.rb +7 -3
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +178 -180
- data/lib/robust_excel_ole/worksheet.rb +7 -4
- data/robust_excel_ole.gemspec +6 -4
- data/spec/bookstore_spec.rb +38 -34
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +89 -44
- data/spec/general_spec.rb +1 -0
- data/spec/range_spec.rb +7 -4
- data/spec/workbook_specs/workbook_close_spec.rb +2 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +34 -18
- data/spec/workbook_specs/workbook_open_spec.rb +112 -71
- data/spec/workbook_specs/workbook_save_spec.rb +173 -5
- data/spec/workbook_specs/workbook_sheet_spec.rb +6 -42
- data/spec/workbook_specs/workbook_unobtr_spec.rb +9 -246
- data/spec/worksheet_spec.rb +21 -5
- metadata +12 -11
| @@ -154,6 +154,23 @@ describe Workbook do | |
| 154 154 |  | 
| 155 155 | 
             
                end
         | 
| 156 156 |  | 
| 157 | 
            +
                context "with saving with the same name in another directory" do
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                  before do
         | 
| 160 | 
            +
                    @book = Workbook.open(@simple_file1)
         | 
| 161 | 
            +
                  end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                  it "should save with the same name in another directory" do
         | 
| 164 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 165 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 166 | 
            +
                      file.puts "garbage"
         | 
| 167 | 
            +
                    end
         | 
| 168 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 169 | 
            +
                    @book.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :forget)
         | 
| 170 | 
            +
                  end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                end
         | 
| 173 | 
            +
             | 
| 157 174 | 
             
                context "with blocked by another file" do
         | 
| 158 175 |  | 
| 159 176 | 
             
                  before do
         | 
| @@ -166,6 +183,156 @@ describe Workbook do | |
| 166 183 | 
             
                    @book2.close(:if_unsaved => :forget)
         | 
| 167 184 | 
             
                  end
         | 
| 168 185 |  | 
| 186 | 
            +
                  it "should raise an error with :obstructed => :raise" do
         | 
| 187 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 188 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 189 | 
            +
                      file.puts "garbage"
         | 
| 190 | 
            +
                    end
         | 
| 191 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 192 | 
            +
                    expect{
         | 
| 193 | 
            +
                      @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :raise)
         | 
| 194 | 
            +
                    }.to raise_error(WorkbookBlocked, /blocked by another workbook/)
         | 
| 195 | 
            +
                  end
         | 
| 196 | 
            +
             | 
| 197 | 
            +
                  it "should close the blocking workbook without saving, and save the current workbook with :if_blocked => :forget" do
         | 
| 198 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 199 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 200 | 
            +
                      file.puts "garbage"
         | 
| 201 | 
            +
                    end
         | 
| 202 | 
            +
                    @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :forget)
         | 
| 203 | 
            +
                    @book.should_not be_alive
         | 
| 204 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 205 | 
            +
                    new_book = Workbook.open(@simple_file_other_path1)
         | 
| 206 | 
            +
                    new_book.should be_a Workbook
         | 
| 207 | 
            +
                    new_book.close
         | 
| 208 | 
            +
                  end
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                  it "should close the blocking workbook without saving even if it is unsaved with :if_blocked => :forget" do
         | 
| 211 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 212 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 213 | 
            +
                      file.puts "garbage"
         | 
| 214 | 
            +
                    end
         | 
| 215 | 
            +
                    sheet = @book.sheet(1)
         | 
| 216 | 
            +
                    cell_value = sheet[1,1].Value
         | 
| 217 | 
            +
                    sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
         | 
| 218 | 
            +
                    @book.Saved.should be false
         | 
| 219 | 
            +
                    @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :forget)
         | 
| 220 | 
            +
                    @book.should_not be_alive
         | 
| 221 | 
            +
                    @book2.should be_alive
         | 
| 222 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 223 | 
            +
                    new_book = Workbook.open(@simple_file_other_path1)
         | 
| 224 | 
            +
                    new_book.should be_a Workbook
         | 
| 225 | 
            +
                    new_book.close
         | 
| 226 | 
            +
                    old_book = Workbook.open(@simple_file1)
         | 
| 227 | 
            +
                    old_sheet = old_book.sheet(1)
         | 
| 228 | 
            +
                    old_sheet[1,1].Value.should == cell_value
         | 
| 229 | 
            +
                    old_book.close
         | 
| 230 | 
            +
                  end
         | 
| 231 | 
            +
             | 
| 232 | 
            +
                  it "should save and close the blocking workbook, and save the current workbook with :if_obstructed => :save" do
         | 
| 233 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 234 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 235 | 
            +
                      file.puts "garbage"
         | 
| 236 | 
            +
                    end
         | 
| 237 | 
            +
                    sheet = @book.sheet(1)
         | 
| 238 | 
            +
                    cell_value = sheet[1,1].Value
         | 
| 239 | 
            +
                    sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
         | 
| 240 | 
            +
                    @book.Saved.should be false
         | 
| 241 | 
            +
                    @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :save)
         | 
| 242 | 
            +
                    @book.should_not be_alive
         | 
| 243 | 
            +
                    @book2.should be_alive
         | 
| 244 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 245 | 
            +
                    new_book = Workbook.open(@simple_file_other_path1)
         | 
| 246 | 
            +
                    new_book.should be_a Workbook
         | 
| 247 | 
            +
                    new_book.close
         | 
| 248 | 
            +
                    old_book = Workbook.open(@simple_file1)
         | 
| 249 | 
            +
                    old_sheet = old_book.sheet(1)
         | 
| 250 | 
            +
                    old_sheet[1,1].Value.should_not == cell_value
         | 
| 251 | 
            +
                    old_book.close
         | 
| 252 | 
            +
                  end
         | 
| 253 | 
            +
             | 
| 254 | 
            +
                  it "should close the blocking workbook if it was saved, and save the current workbook with :if_obstructed => :close_if_saved" do
         | 
| 255 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 256 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 257 | 
            +
                      file.puts "garbage"
         | 
| 258 | 
            +
                    end
         | 
| 259 | 
            +
                    @book.Saved.should be true
         | 
| 260 | 
            +
                    @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :close_if_saved)
         | 
| 261 | 
            +
                    @book.should_not be_alive
         | 
| 262 | 
            +
                    @book2.should be_alive
         | 
| 263 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 264 | 
            +
                    new_book = Workbook.open(@simple_file_other_path1)
         | 
| 265 | 
            +
                    new_book.should be_a Workbook
         | 
| 266 | 
            +
                    new_book.close
         | 
| 267 | 
            +
                  end
         | 
| 268 | 
            +
             | 
| 269 | 
            +
                  it "should raise an error if the blocking workbook was unsaved with :if_blocked => :close_if_saved" do
         | 
| 270 | 
            +
                    sheet = @book.sheet(1)
         | 
| 271 | 
            +
                    cell_value = sheet[1,1].Value
         | 
| 272 | 
            +
                    sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
         | 
| 273 | 
            +
                    @book.Saved.should be false      
         | 
| 274 | 
            +
                    expect{
         | 
| 275 | 
            +
                      @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :close_if_saved)
         | 
| 276 | 
            +
                    }.to raise_error(WorkbookBlocked, /blocking workbook is unsaved: "workbook.xls"/)
         | 
| 277 | 
            +
                  end
         | 
| 278 | 
            +
             | 
| 279 | 
            +
                  it "should raise an error with an invalid option" do
         | 
| 280 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 281 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 282 | 
            +
                      file.puts "garbage"
         | 
| 283 | 
            +
                    end
         | 
| 284 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 285 | 
            +
                    expect{
         | 
| 286 | 
            +
                      @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :invalid)
         | 
| 287 | 
            +
                    }.to raise_error(OptionInvalid, /invalid option/)
         | 
| 288 | 
            +
                    # }.to raise_error(OptionInvalid, ":if_blocked: invalid option: :invalid" +
         | 
| 289 | 
            +
                    #  "\nHint: Valid values are :raise, :forget, :save, :if_closed_saveo")
         | 
| 290 | 
            +
                  end
         | 
| 291 | 
            +
             | 
| 292 | 
            +
                  it "should raise an error by default" do
         | 
| 293 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 294 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 295 | 
            +
                      file.puts "garbage"
         | 
| 296 | 
            +
                    end
         | 
| 297 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 298 | 
            +
                    expect{
         | 
| 299 | 
            +
                      @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite)
         | 
| 300 | 
            +
                    }.to raise_error(WorkbookBlocked, /blocked by another workbook/)
         | 
| 301 | 
            +
                  end
         | 
| 302 | 
            +
             | 
| 303 | 
            +
                  it "should raise an error if the file does not exist and an workbook with the same name and other path exists" do
         | 
| 304 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 305 | 
            +
                    File.exist?(@simple_file_other_path1).should be false
         | 
| 306 | 
            +
                    expect{
         | 
| 307 | 
            +
                      @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_blocked => :raise)
         | 
| 308 | 
            +
                      }.to raise_error(WorkbookBlocked, /blocked by another workbook/)
         | 
| 309 | 
            +
                  end
         | 
| 310 | 
            +
             | 
| 311 | 
            +
                  it "should raise an error if the file exists and an workbook with the same name and other path exists" do
         | 
| 312 | 
            +
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 313 | 
            +
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 314 | 
            +
                      file.puts "garbage"
         | 
| 315 | 
            +
                    end
         | 
| 316 | 
            +
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 317 | 
            +
                    expect{
         | 
| 318 | 
            +
                      @book.save_as(@simple_file_other_path1, :if_exists => :raise, :if_blocked => :raise)
         | 
| 319 | 
            +
                    }.to raise_error(FileAlreadyExists, /file already exists: "workbook.xls"/)
         | 
| 320 | 
            +
                  end
         | 
| 321 | 
            +
             | 
| 322 | 
            +
                end
         | 
| 323 | 
            +
             | 
| 324 | 
            +
                context "with obstructed by another file" do
         | 
| 325 | 
            +
             | 
| 326 | 
            +
                  before do
         | 
| 327 | 
            +
                    @book = Workbook.open(@simple_file1)
         | 
| 328 | 
            +
                    @book2 = Workbook.open(@another_simple_file)
         | 
| 329 | 
            +
                  end
         | 
| 330 | 
            +
             | 
| 331 | 
            +
                  after do
         | 
| 332 | 
            +
                    @book.close(:if_unsaved => :forget)
         | 
| 333 | 
            +
                    @book2.close(:if_unsaved => :forget)
         | 
| 334 | 
            +
                  end
         | 
| 335 | 
            +
             | 
| 169 336 | 
             
                  it "should raise an error with :obstructed => :raise" do
         | 
| 170 337 | 
             
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 171 338 | 
             
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| @@ -177,7 +344,7 @@ describe Workbook do | |
| 177 344 | 
             
                    }.to raise_error(WorkbookBlocked, /blocked by another workbook/)
         | 
| 178 345 | 
             
                  end
         | 
| 179 346 |  | 
| 180 | 
            -
                  it "should close the blocking workbook without saving, and save the current workbook with : | 
| 347 | 
            +
                  it "should close the blocking workbook without saving, and save the current workbook with :if_blocked => :forget" do
         | 
| 181 348 | 
             
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 182 349 | 
             
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 183 350 | 
             
                      file.puts "garbage"
         | 
| @@ -234,7 +401,7 @@ describe Workbook do | |
| 234 401 | 
             
                    old_book.close
         | 
| 235 402 | 
             
                  end
         | 
| 236 403 |  | 
| 237 | 
            -
                  it "should close the blocking workbook if it was saved, and save the current workbook with : | 
| 404 | 
            +
                  it "should close the blocking workbook if it was saved, and save the current workbook with :if_blokced => :close_if_saved" do
         | 
| 238 405 | 
             
                    File.delete @simple_file_other_path1 rescue nil
         | 
| 239 406 | 
             
                    File.open(@simple_file_other_path1,"w") do | file |
         | 
| 240 407 | 
             
                      file.puts "garbage"
         | 
| @@ -249,7 +416,7 @@ describe Workbook do | |
| 249 416 | 
             
                    new_book.close
         | 
| 250 417 | 
             
                  end
         | 
| 251 418 |  | 
| 252 | 
            -
                  it "should raise an error if the blocking workbook was unsaved with : | 
| 419 | 
            +
                  it "should raise an error if the blocking workbook was unsaved with :if_blocked => :close_if_saved" do
         | 
| 253 420 | 
             
                    sheet = @book.sheet(1)
         | 
| 254 421 | 
             
                    cell_value = sheet[1,1].Value
         | 
| 255 422 | 
             
                    sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
         | 
| @@ -267,8 +434,9 @@ describe Workbook do | |
| 267 434 | 
             
                    File.exist?(@simple_file_other_path1).should be true
         | 
| 268 435 | 
             
                    expect{
         | 
| 269 436 | 
             
                      @book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :invalid)
         | 
| 270 | 
            -
                    }.to raise_error(OptionInvalid,  | 
| 271 | 
            -
             | 
| 437 | 
            +
                    }.to raise_error(OptionInvalid, /invalid option/)
         | 
| 438 | 
            +
                    #}.to raise_error(OptionInvalid, ":if_blocked: invalid option: :invalid" +
         | 
| 439 | 
            +
                    #  "\nHint: Valid values are :raise, :forget, :save, :save_if_closed")
         | 
| 272 440 | 
             
                  end
         | 
| 273 441 |  | 
| 274 442 | 
             
                  it "should raise an error by default" do
         | 
| @@ -191,47 +191,11 @@ describe Workbook do | |
| 191 191 | 
             
                end
         | 
| 192 192 | 
             
              end
         | 
| 193 193 |  | 
| 194 | 
            -
              describe "add_empty_sheet" do
         | 
| 195 | 
            -
                
         | 
| 196 | 
            -
                before do
         | 
| 197 | 
            -
                  @book = Workbook.open(@simple_file)
         | 
| 198 | 
            -
                  @sheet = @book.sheet(1)
         | 
| 199 | 
            -
                end
         | 
| 200 | 
            -
             | 
| 201 | 
            -
                after do
         | 
| 202 | 
            -
                  @book.close(:if_unsaved => :forget)
         | 
| 203 | 
            -
                end
         | 
| 204 | 
            -
             | 
| 205 | 
            -
                it "should add empty sheet" do
         | 
| 206 | 
            -
                  @book.ole_workbook.Worksheets.Count.should == 3
         | 
| 207 | 
            -
                  @book.add_empty_sheet
         | 
| 208 | 
            -
                  @book.ole_workbook.Worksheets.Count.should == 4
         | 
| 209 | 
            -
                end
         | 
| 210 | 
            -
             | 
| 211 | 
            -
                it "should add an empty sheet and return this added sheet" do
         | 
| 212 | 
            -
                  sheet = @book.add_empty_sheet
         | 
| 213 | 
            -
                  copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
         | 
| 214 | 
            -
                  sheet.name.should eq copyed_sheet.name
         | 
| 215 | 
            -
                end
         | 
| 216 | 
            -
             | 
| 217 | 
            -
                it "should return new sheet" do
         | 
| 218 | 
            -
                  @book.add_empty_sheet(:as => 'new sheet').name.should eq 'new sheet'
         | 
| 219 | 
            -
                end
         | 
| 220 | 
            -
             | 
| 221 | 
            -
                it "should add the first sheet" do
         | 
| 222 | 
            -
                  @book.add_empty_sheet(:before => @sheet).name.should eq @book.sheet(1).name
         | 
| 223 | 
            -
                end
         | 
| 224 | 
            -
             | 
| 225 | 
            -
                it "should add the second sheet" do
         | 
| 226 | 
            -
                  @book.add_empty_sheet(:after => @sheet).name.should eq @book.sheet(2).name
         | 
| 227 | 
            -
                end
         | 
| 228 | 
            -
              end  
         | 
| 229 | 
            -
             | 
| 230 194 | 
             
              describe "copy_sheet" do
         | 
| 231 195 |  | 
| 232 196 | 
             
                before do
         | 
| 233 | 
            -
                   | 
| 234 | 
            -
                  @ | 
| 197 | 
            +
                  @book = Workbook.open(@simple_file)
         | 
| 198 | 
            +
                  @book2 = Workbook.open(@file_with_references)
         | 
| 235 199 | 
             
                  @sheet = @book.sheet(1)
         | 
| 236 200 | 
             
                  @another_book = Workbook.open(@another_simple_file)
         | 
| 237 201 | 
             
                end
         | 
| @@ -242,10 +206,10 @@ describe Workbook do | |
| 242 206 | 
             
                end
         | 
| 243 207 |  | 
| 244 208 | 
             
                it "should copy the second sheet, append it and leave the references so far" do
         | 
| 245 | 
            -
                  @ | 
| 246 | 
            -
                  @ | 
| 247 | 
            -
                  @ | 
| 248 | 
            -
                  @ | 
| 209 | 
            +
                  @book2.add_sheet(@book2.sheet(2), :after => @book2.sheet(3))
         | 
| 210 | 
            +
                  @book2.sheet(1)[2,1].Value.should == "x"
         | 
| 211 | 
            +
                  @book2.sheet(1)[2,2].Value.should == "y"
         | 
| 212 | 
            +
                  @book2.sheet(1)[2,3].Value.should == "z"
         | 
| 249 213 | 
             
                end
         | 
| 250 214 |  | 
| 251 215 | 
             
                it "should copy and append a given sheet" do
         | 
| @@ -53,222 +53,6 @@ describe Workbook do | |
| 53 53 | 
             
                  expect{unobtrusively_ok?}.to_not raise_error
         | 
| 54 54 | 
             
                end
         | 
| 55 55 |  | 
| 56 | 
            -
            =begin
         | 
| 57 | 
            -
                describe "with already open Excel instances and workbooks" do
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                  before do
         | 
| 60 | 
            -
                    @ole_excel1 = WIN32OLE.new('Excel.Application')
         | 
| 61 | 
            -
                    @ole_excel2 = WIN32OLE.new('Excel.Application')
         | 
| 62 | 
            -
                  end
         | 
| 63 | 
            -
             | 
| 64 | 
            -
                  context "with open unsaved workbook" do
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                    before do        
         | 
| 67 | 
            -
                      @book1 = Workbook.open(@simple_file1)
         | 
| 68 | 
            -
                      @book1.sheet(1)[1,1] = "foo"
         | 
| 69 | 
            -
                      #@ole_workbook1 = @ole_excel1.Workbooks.Open(@simple_file1, { 'ReadOnly' => false })
         | 
| 70 | 
            -
                      #@old_value = @ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value
         | 
| 71 | 
            -
                      #@ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value = 
         | 
| 72 | 
            -
                      #  @old_value == "foo" ? "bar" : "foo"
         | 
| 73 | 
            -
                    end
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                    context "with writability" do
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                      it "should open as read-write by default" do
         | 
| 78 | 
            -
                        Workbook.unobtrusively(@simple_file1) do |book|
         | 
| 79 | 
            -
                          book.Readonly.should be false
         | 
| 80 | 
            -
                          #book.filename.should == @ole_workbook1.Fullname.tr('\\','/')
         | 
| 81 | 
            -
                          #book.excel.ole_excel.Hwnd.should == @ole_excel1.Hwnd
         | 
| 82 | 
            -
                          book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
         | 
| 83 | 
            -
                        end
         | 
| 84 | 
            -
                        #@ole_workbook1.Saved.should be false
         | 
| 85 | 
            -
                        Excel.kill_all
         | 
| 86 | 
            -
                        sleep 1
         | 
| 87 | 
            -
                        book2 = Workbook.open(@simple_file1)
         | 
| 88 | 
            -
                        #book2.sheet(1)[1,1].Value.should == @old_value
         | 
| 89 | 
            -
                      end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                      it "should open not writable" do
         | 
| 92 | 
            -
                        Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
         | 
| 93 | 
            -
                          book.ReadOnly.should be false
         | 
| 94 | 
            -
                          book.filename.should == @ole_workbook1.Fullname.tr('\\','/')
         | 
| 95 | 
            -
                          book.excel.ole_excel.Hwnd.should == @ole_excel1.Hwnd
         | 
| 96 | 
            -
                          book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
         | 
| 97 | 
            -
                        end
         | 
| 98 | 
            -
                        @book.Saved.should be false
         | 
| 99 | 
            -
                        @book.sheet(1)[1,1].Value.should_not == @old_value
         | 
| 100 | 
            -
                        Excel.kill_all
         | 
| 101 | 
            -
                        sleep 1
         | 
| 102 | 
            -
                        book2 = Workbook.open(@simple_file1)
         | 
| 103 | 
            -
                        book2.sheet(1)[1,1].Value.should_not == @old_value
         | 
| 104 | 
            -
                      end
         | 
| 105 | 
            -
                    end
         | 
| 106 | 
            -
             | 
| 107 | 
            -
                    context "further tests" do
         | 
| 108 | 
            -
             | 
| 109 | 
            -
                      it "should write in the outer and not in the inner block" do
         | 
| 110 | 
            -
                        Workbook.unobtrusively(@simple_file1) do |book|
         | 
| 111 | 
            -
                          @old_value = book.sheet(1)[1,1].Value
         | 
| 112 | 
            -
                          book.ReadOnly.should be false
         | 
| 113 | 
            -
                          book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo" 
         | 
| 114 | 
            -
                          book.Saved.should be false
         | 
| 115 | 
            -
                          book.sheet(1)[1,1].Value.should_not == @old_value
         | 
| 116 | 
            -
                          Workbook.unobtrusively(@simple_file1, :writable => false) do |book2|
         | 
| 117 | 
            -
                            book2.should == book
         | 
| 118 | 
            -
                            book2.ReadOnly.should be false
         | 
| 119 | 
            -
                            book2.Saved.should be false
         | 
| 120 | 
            -
                            book2.sheet(1)[1,1].Value.should_not == @old_value
         | 
| 121 | 
            -
                            book2.sheet(1)[1,1] = book2.sheet(1)[1,1].Value == "foo" ? "bar" : "foo" 
         | 
| 122 | 
            -
                            book2.sheet(1)[1,1].Value.should == @old_value
         | 
| 123 | 
            -
                          end
         | 
| 124 | 
            -
                          book.should be_alive
         | 
| 125 | 
            -
                          book.Saved.should be false
         | 
| 126 | 
            -
                          book.sheet(1)[1,1].Value.should == @old_value            
         | 
| 127 | 
            -
                        end
         | 
| 128 | 
            -
                        book = Workbook.open(@simple_file1)
         | 
| 129 | 
            -
                        book.sheet(1)[1,1].Value.should == @old_value
         | 
| 130 | 
            -
                      end
         | 
| 131 | 
            -
             | 
| 132 | 
            -
                      it "should use the excel of the book and keep open the book" do
         | 
| 133 | 
            -
                        @book = Workbook.open(@simple_file1)
         | 
| 134 | 
            -
                        excel = Excel.new(:reuse => false)
         | 
| 135 | 
            -
                        sheet = @book.sheet(1)
         | 
| 136 | 
            -
                        old_cell_value = sheet[1,1].Value
         | 
| 137 | 
            -
                        @book.close
         | 
| 138 | 
            -
                        @book.should_not be_alive
         | 
| 139 | 
            -
                        Workbook.unobtrusively(@simple_file, :keep_open => true) do |book|
         | 
| 140 | 
            -
                          book.should be_a Workbook
         | 
| 141 | 
            -
                          book.excel.should == @book.excel
         | 
| 142 | 
            -
                          book.excel.should_not == excel
         | 
| 143 | 
            -
                          sheet = book.sheet(1)
         | 
| 144 | 
            -
                          cell = sheet[1,1]
         | 
| 145 | 
            -
                          sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
         | 
| 146 | 
            -
                          book.Saved.should be false
         | 
| 147 | 
            -
                        end
         | 
| 148 | 
            -
                        @book.should be_alive
         | 
| 149 | 
            -
                        @book.close
         | 
| 150 | 
            -
                        new_book = Workbook.open(@simple_file1)
         | 
| 151 | 
            -
                        sheet = new_book.sheet(1)
         | 
| 152 | 
            -
                        sheet[1,1].Value.should_not == old_cell_value
         | 
| 153 | 
            -
                      end
         | 
| 154 | 
            -
             | 
| 155 | 
            -
                      it "should use the excel of the book and keep open the book" do
         | 
| 156 | 
            -
                        @book = Workbook.open(@simple_file1)
         | 
| 157 | 
            -
                        excel = Excel.new(:reuse => false)
         | 
| 158 | 
            -
                        sheet = @book.sheet(1)
         | 
| 159 | 
            -
                        old_cell_value = sheet[1,1].Value
         | 
| 160 | 
            -
                        @book.close
         | 
| 161 | 
            -
                        @book.should_not be_alive
         | 
| 162 | 
            -
                        Workbook.unobtrusively(@simple_file, :if_closed => :new) do |book|
         | 
| 163 | 
            -
                          book.should be_a Workbook
         | 
| 164 | 
            -
                          book.should be_alive
         | 
| 165 | 
            -
                          book.excel.should_not == @book.excel
         | 
| 166 | 
            -
                          book.excel.should_not == excel
         | 
| 167 | 
            -
                          sheet = book.sheet(1)
         | 
| 168 | 
            -
                          cell = sheet[1,1]
         | 
| 169 | 
            -
                          sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
         | 
| 170 | 
            -
                          book.Saved.should be false
         | 
| 171 | 
            -
                        end
         | 
| 172 | 
            -
                        @book.should_not be_alive
         | 
| 173 | 
            -
                        new_book = Workbook.open(@simple_file1)
         | 
| 174 | 
            -
                        sheet = new_book.sheet(1)
         | 
| 175 | 
            -
                        sheet[1,1].Value.should_not == old_cell_value
         | 
| 176 | 
            -
                      end
         | 
| 177 | 
            -
             | 
| 178 | 
            -
                      it "should use a given Excel" do
         | 
| 179 | 
            -
                        @book = Workbook.open(@simple_file1)
         | 
| 180 | 
            -
                        @book.close
         | 
| 181 | 
            -
                        new_excel = Excel.new(:reuse => false)
         | 
| 182 | 
            -
                        another_excel = Excel.new(:reuse => false)
         | 
| 183 | 
            -
                        Workbook.unobtrusively(@simple_file1, :if_closed => another_excel) do |book|
         | 
| 184 | 
            -
                          book.excel.should_not == @book.excel
         | 
| 185 | 
            -
                          book.excel.should_not == new_excel
         | 
| 186 | 
            -
                          book.excel.should == another_excel
         | 
| 187 | 
            -
                        end
         | 
| 188 | 
            -
                      end
         | 
| 189 | 
            -
             | 
| 190 | 
            -
                      it "should reuse Excel" do
         | 
| 191 | 
            -
                        new_excel = Excel.new(:reuse => false)
         | 
| 192 | 
            -
                        Workbook.unobtrusively(@simple_file1, :if_closed => :reuse) do |book|
         | 
| 193 | 
            -
                        book.excel.should == @book.excel
         | 
| 194 | 
            -
                        book.excel.should_not == new_excel
         | 
| 195 | 
            -
                      end
         | 
| 196 | 
            -
             | 
| 197 | 
            -
                      it "should open unobtrusively the closed book in the most recent Excel where it was open before" do      
         | 
| 198 | 
            -
                        @book1 = Workbook.open(@simple_file1)
         | 
| 199 | 
            -
                        @book2 = Workbook.open(@simple_file1, :force_excel => :new)
         | 
| 200 | 
            -
                        @book1.Readonly.should == false
         | 
| 201 | 
            -
                        @book2.Readonly.should == true
         | 
| 202 | 
            -
                        old_sheet = @book1.sheet(1)
         | 
| 203 | 
            -
                        @old_cell_value = old_sheet[1,1].Value
         | 
| 204 | 
            -
                        @book1.close
         | 
| 205 | 
            -
                        @book2.close
         | 
| 206 | 
            -
                        @book1.should_not be_alive
         | 
| 207 | 
            -
                        @book2.should_not be_alive
         | 
| 208 | 
            -
                        Workbook.unobtrusively(@simple_file1) do |book| 
         | 
| 209 | 
            -
                          book.excel.should_not == @book2.excel
         | 
| 210 | 
            -
                          book.excel.should == @book1.excel
         | 
| 211 | 
            -
                          book.ReadOnly.should == false
         | 
| 212 | 
            -
                          sheet = book.sheet(1)
         | 
| 213 | 
            -
                          cell = sheet[1,1]
         | 
| 214 | 
            -
                          sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
         | 
| 215 | 
            -
                          book.Saved.should be false
         | 
| 216 | 
            -
                        end
         | 
| 217 | 
            -
                        new_book = Workbook.open(@simple_file1)
         | 
| 218 | 
            -
                        sheet = new_book.sheet(1)
         | 
| 219 | 
            -
                        sheet[1,1].Value.should_not == @old_cell_value
         | 
| 220 | 
            -
                      end
         | 
| 221 | 
            -
                    end
         | 
| 222 | 
            -
                  end
         | 
| 223 | 
            -
             | 
| 224 | 
            -
                  context "with open unsaved read-only workbook" do
         | 
| 225 | 
            -
             | 
| 226 | 
            -
                    before do        
         | 
| 227 | 
            -
                      @ole_workbook1 = @ole_excel1.Workbooks.Open(@simple_file1, { 'ReadOnly' => true })
         | 
| 228 | 
            -
                      @old_value = @ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value
         | 
| 229 | 
            -
                      @ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value = 
         | 
| 230 | 
            -
                        @old_value == "foo" ? "bar" : "foo"
         | 
| 231 | 
            -
                    end
         | 
| 232 | 
            -
             | 
| 233 | 
            -
                    context "with writability" do
         | 
| 234 | 
            -
             | 
| 235 | 
            -
                      it "should open as read-only by default" do
         | 
| 236 | 
            -
                        Workbook.unobtrusively(@simple_file1) do |book|
         | 
| 237 | 
            -
                          book.Readonly.should be true
         | 
| 238 | 
            -
                          book.filename.should == @ole_workbook1.Fullname.tr('\\','/')
         | 
| 239 | 
            -
                          book.excel.ole_excel.Hwnd.should == @ole_excel1.Hwnd
         | 
| 240 | 
            -
                          book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
         | 
| 241 | 
            -
                        end
         | 
| 242 | 
            -
                        @ole_workbook1.Saved.should be false
         | 
| 243 | 
            -
                        @ole_workbook1.ReadOnly.should be true          
         | 
| 244 | 
            -
                        @ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value.should_not == @old_value
         | 
| 245 | 
            -
                        Excel.kill_all
         | 
| 246 | 
            -
                        sleep 1
         | 
| 247 | 
            -
                        book2 = Workbook.open(@simple_file1)
         | 
| 248 | 
            -
                        book2.sheet(1)[1,1].Value.should_not == @old_value
         | 
| 249 | 
            -
                      end
         | 
| 250 | 
            -
             | 
| 251 | 
            -
                      it "should open not writable" do
         | 
| 252 | 
            -
                        Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
         | 
| 253 | 
            -
                          book.ReadOnly.should be true
         | 
| 254 | 
            -
                          book.filename.should == @ole_workbook1.Fullname.tr('\\','/')
         | 
| 255 | 
            -
                          book.excel.ole_excel.Hwnd.should == @ole_excel1.Hwnd
         | 
| 256 | 
            -
                          book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
         | 
| 257 | 
            -
                        end
         | 
| 258 | 
            -
                        @ole_workbook1.Saved.should be false
         | 
| 259 | 
            -
                        @ole_workbook1.ReadOnly.should be true          
         | 
| 260 | 
            -
                        @ole_workbook1.Worksheets.Item(1).Cells.Item(1, 1).Value.should_not == @old_value
         | 
| 261 | 
            -
                        Excel.kill_all
         | 
| 262 | 
            -
                        sleep 1
         | 
| 263 | 
            -
                        book2 = Workbook.open(@simple_file1)
         | 
| 264 | 
            -
                        book2.sheet(1)[1,1].Value.should == @old_value
         | 
| 265 | 
            -
                      end
         | 
| 266 | 
            -
                    end
         | 
| 267 | 
            -
                  end
         | 
| 268 | 
            -
                end
         | 
| 269 | 
            -
              end
         | 
| 270 | 
            -
            =end
         | 
| 271 | 
            -
             | 
| 272 56 | 
             
                describe "block transparency" do
         | 
| 273 57 |  | 
| 274 58 | 
             
                  it "should return correct value of the block" do
         | 
| @@ -314,28 +98,6 @@ describe Workbook do | |
| 314 98 |  | 
| 315 99 | 
             
                end
         | 
| 316 100 |  | 
| 317 | 
            -
                describe "connecting to unknown workbooks" do
         | 
| 318 | 
            -
             | 
| 319 | 
            -
                  context "with one unknown workbook" do
         | 
| 320 | 
            -
             | 
| 321 | 
            -
                    before do
         | 
| 322 | 
            -
                      ole_e1 = WIN32OLE.new('Excel.Application')
         | 
| 323 | 
            -
                      ws = ole_e1.Workbooks
         | 
| 324 | 
            -
                      abs_filename = General.absolute_path(@simple_file1).tr('/','\\')
         | 
| 325 | 
            -
                      @ole_wb = ws.Open(abs_filename)
         | 
| 326 | 
            -
                    end
         | 
| 327 | 
            -
             | 
| 328 | 
            -
                    it "should connect to an unknown workbook" do
         | 
| 329 | 
            -
                      Workbook.unobtrusively(@simple_file1) do |book|
         | 
| 330 | 
            -
                        book.filename.should == @simple_file1
         | 
| 331 | 
            -
                        book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
         | 
| 332 | 
            -
                      end
         | 
| 333 | 
            -
                    end
         | 
| 334 | 
            -
             | 
| 335 | 
            -
                  end
         | 
| 336 | 
            -
             | 
| 337 | 
            -
                end
         | 
| 338 | 
            -
             | 
| 339 101 | 
             
                describe "writability" do
         | 
| 340 102 |  | 
| 341 103 | 
             
                  context "with no book" do
         | 
| @@ -618,7 +380,7 @@ describe Workbook do | |
| 618 380 |  | 
| 619 381 | 
             
                    it "should force to read-write" do
         | 
| 620 382 | 
             
                      Workbook.unobtrusively(@simple_file1, :writable => true) do |book|
         | 
| 621 | 
            -
                        book. | 
| 383 | 
            +
                        book.ReadOnly.should be false
         | 
| 622 384 | 
             
                        book.should == @book
         | 
| 623 385 | 
             
                        book.filename.should == @book.filename
         | 
| 624 386 | 
             
                        book.excel.should == @book.excel
         | 
| @@ -1263,11 +1025,12 @@ describe Workbook do | |
| 1263 1025 | 
             
                  end
         | 
| 1264 1026 |  | 
| 1265 1027 | 
             
                  it "should open in another Excel instance if the given Excel instance is not alive" do
         | 
| 1266 | 
            -
                     | 
| 1028 | 
            +
                    @excel1.close
         | 
| 1267 1029 | 
             
                    sleep 2
         | 
| 1268 1030 | 
             
                    expect{
         | 
| 1269 1031 | 
             
                      Workbook.unobtrusively(@simple_file, :if_closed => @excel2) do |book|
         | 
| 1270 1032 | 
             
                        book.should be_alive
         | 
| 1033 | 
            +
                        book.excel.should == @excel2
         | 
| 1271 1034 | 
             
                      end
         | 
| 1272 1035 | 
             
                    }.to_not raise_error
         | 
| 1273 1036 | 
             
                  end
         | 
| @@ -1555,18 +1318,18 @@ describe Workbook do | |
| 1555 1318 | 
             
                      book.excel.displayalerts.should == :if_visible
         | 
| 1556 1319 | 
             
                      @another_excel = book.excel
         | 
| 1557 1320 | 
             
                    end
         | 
| 1558 | 
            -
                    Workbook.unobtrusively(@simple_file1, :if_closed => : | 
| 1559 | 
            -
                      book.excel. | 
| 1321 | 
            +
                    Workbook.unobtrusively(@simple_file1, :if_closed => :current) do |book|
         | 
| 1322 | 
            +
                      book.excel.should_not == @book.excel
         | 
| 1560 1323 | 
             
                      book.excel.should_not == new_excel
         | 
| 1324 | 
            +
                      book.excel.should == @another_excel
         | 
| 1561 1325 | 
             
                      book.excel.visible.should be false
         | 
| 1562 1326 | 
             
                      book.excel.displayalerts.should == :if_visible
         | 
| 1563 | 
            -
                      book.excel.should_not == @another_excel 
         | 
| 1564 1327 | 
             
                    end
         | 
| 1565 1328 | 
             
                  end
         | 
| 1566 1329 |  | 
| 1567 1330 | 
             
                  it "should reuse Excel" do
         | 
| 1568 1331 | 
             
                    new_excel = Excel.new(:reuse => false)
         | 
| 1569 | 
            -
                    Workbook.unobtrusively(@simple_file1, :if_closed => : | 
| 1332 | 
            +
                    Workbook.unobtrusively(@simple_file1, :if_closed => :current) do |book|
         | 
| 1570 1333 | 
             
                      book.excel.should == @book.excel
         | 
| 1571 1334 | 
             
                      book.excel.should_not == new_excel
         | 
| 1572 1335 | 
             
                    end
         | 
| @@ -1863,8 +1626,8 @@ describe Workbook do | |
| 1863 1626 |  | 
| 1864 1627 | 
             
                  it "should open unobtrusively the closed book in the most recent Excel where it was open before" do      
         | 
| 1865 1628 | 
             
                    Workbook.unobtrusively(@simple_file1) do |book| 
         | 
| 1866 | 
            -
                      book.excel. | 
| 1867 | 
            -
                      book.excel. | 
| 1629 | 
            +
                      book.excel.should == @book2.excel
         | 
| 1630 | 
            +
                      book.excel.should_not == @book1.excel
         | 
| 1868 1631 | 
             
                      book.ReadOnly.should == false
         | 
| 1869 1632 | 
             
                      sheet = book.sheet(1)
         | 
| 1870 1633 | 
             
                      cell = sheet[1,1]
         |