2014-05-09 03:32:12 +08:00
# pragma once
# include <iostream>
# include <cxxtest/TestSuite.h>
2015-10-15 06:05:13 +08:00
# include <xlnt/writer/worksheet_writer.hpp>
2014-05-09 03:32:12 +08:00
2014-06-06 04:19:31 +08:00
class test_worksheet : public CxxTest : : TestSuite
2014-05-09 03:32:12 +08:00
{
public :
void test_new_worksheet ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws = wb_ . create_sheet ( ) ;
2014-07-27 04:19:15 +08:00
TS_ASSERT ( wb_ = = ws . get_parent ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
2014-05-09 03:32:12 +08:00
void test_get_cell ( )
{
2014-07-27 04:19:15 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
auto cell = ws . get_cell ( xlnt : : cell_reference ( 1 , 1 ) ) ;
TS_ASSERT_EQUALS ( cell . get_reference ( ) , " A1 " ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_worksheet_dimension ( )
2014-05-09 03:32:12 +08:00
{
2015-10-14 01:56:07 +08:00
xlnt : : worksheet ws ( wb_ ) ;
TS_ASSERT_EQUALS ( " A1:A1 " , ws . calculate_dimension ( ) ) ;
ws . get_cell ( " B12 " ) . set_value ( " AAA " ) ;
TS_ASSERT_EQUALS ( " B12:B12 " , ws . calculate_dimension ( ) ) ;
2014-07-19 04:20:41 +08:00
}
2015-10-14 01:56:07 +08:00
void test_squared_range ( )
2014-07-19 04:20:41 +08:00
{
2015-10-14 01:56:07 +08:00
xlnt : : worksheet ws ( wb_ ) ;
const std : : vector < std : : vector < std : : string > > expected =
{
{ " A1 " , " B1 " , " C1 " } ,
{ " A2 " , " B2 " , " C2 " } ,
{ " A3 " , " B3 " , " C3 " } ,
{ " A4 " , " B4 " , " C4 " }
} ;
auto rows = ws . get_squared_range ( 1 , 1 , 3 , 4 ) ;
auto expected_row_iter = expected . begin ( ) ;
for ( auto row : rows )
{
auto expected_cell_iter = ( * expected_row_iter ) . begin ( ) ;
for ( auto cell : row )
{
TS_ASSERT_EQUALS ( cell . get_reference ( ) , * expected_cell_iter ) ;
expected_cell_iter + + ;
}
expected_row_iter + + ;
}
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_iter_rows_1 ( )
2014-05-09 03:32:12 +08:00
{
2015-10-14 01:56:07 +08:00
row_t row = 0 ;
column_t column = 0 ;
std : : string coordinate = " A1 " ;
xlnt : : worksheet ws ( wb_ ) ;
ws . get_cell ( " A1 " ) . set_value ( " first " ) ;
ws . get_cell ( " C9 " ) . set_value ( " last " ) ;
TS_ASSERT_EQUALS ( ws . calculate_dimension ( ) , " A1:C9 " ) ;
TS_ASSERT_EQUALS ( ws . rows ( ) [ row ] [ column ] . get_reference ( ) , coordinate ) ;
row = 8 ;
column = 2 ;
coordinate = " C9 " ;
TS_ASSERT_EQUALS ( ws . rows ( ) [ row ] [ column ] . get_reference ( ) , coordinate ) ;
2014-05-09 03:32:12 +08:00
}
2014-07-27 04:19:15 +08:00
2015-10-14 01:56:07 +08:00
void test_iter_rows_2 ( )
2014-07-27 04:19:15 +08:00
{
2015-10-14 01:56:07 +08:00
xlnt : : worksheet ws ( wb_ ) ;
const std : : vector < std : : vector < std : : string > > expected =
{
{ " A1 " , " B1 " , " C1 " } ,
{ " A2 " , " B2 " , " C2 " } ,
{ " A3 " , " B3 " , " C3 " } ,
{ " A4 " , " B4 " , " C4 " }
} ;
auto rows = ws . rows ( " A1:C4 " ) ;
auto expected_row_iter = expected . begin ( ) ;
for ( auto row : rows )
{
auto expected_cell_iter = ( * expected_row_iter ) . begin ( ) ;
for ( auto cell : row )
{
TS_ASSERT_EQUALS ( cell . get_reference ( ) , * expected_cell_iter ) ;
expected_cell_iter + + ;
}
expected_row_iter + + ;
}
2014-07-27 04:19:15 +08:00
}
2015-10-14 01:56:07 +08:00
void test_iter_rows_offset ( )
2014-05-09 03:32:12 +08:00
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
auto rows = ws . rows ( " A1:C4 " , 1 , 3 ) ;
const std : : vector < std : : vector < std : : string > > expected =
{
{ " D2 " , " E2 " , " F2 " } ,
{ " D3 " , " E3 " , " F3 " } ,
{ " D4 " , " E4 " , " F4 " } ,
{ " D5 " , " E5 " , " F5 " }
} ;
auto expected_row_iter = expected . begin ( ) ;
for ( auto row : rows )
{
auto expected_cell_iter = ( * expected_row_iter ) . begin ( ) ;
for ( auto cell : row )
{
TS_ASSERT_EQUALS ( cell . get_reference ( ) , * expected_cell_iter ) ;
expected_cell_iter + + ;
}
expected_row_iter + + ;
}
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_worksheet_recwarn ( )
2014-05-09 03:32:12 +08:00
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
auto rows = ws . get_range ( " A1:D4 " ) ;
TS_SKIP ( " " ) ; // what's recwarn?
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_get_named_range ( )
2014-05-09 03:32:12 +08:00
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
wb_ . create_named_range ( " test_range " , ws , " C5 " ) ;
2014-05-21 22:20:30 +08:00
auto xlrange = ws . get_named_range ( " test_range " ) ;
2014-07-20 04:59:05 +08:00
TS_ASSERT_EQUALS ( 1 , xlrange . length ( ) ) ;
2014-05-22 05:48:51 +08:00
TS_ASSERT_EQUALS ( 1 , xlrange [ 0 ] . num_cells ( ) ) ;
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS ( 5 , xlrange [ 0 ] [ 0 ] . get_row ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_get_bad_named_range ( )
2014-05-09 03:32:12 +08:00
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2014-07-24 04:00:09 +08:00
TS_ASSERT_THROWS ( ws . get_named_range ( " bad_range " ) , xlnt : : named_range_exception ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_get_named_range_wrong_sheet ( )
2014-05-09 03:32:12 +08:00
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws1 ( wb_ ) ;
xlnt : : worksheet ws2 ( wb_ ) ;
wb_ . create_named_range ( " wrong_sheet_range " , ws1 , " C5 " ) ;
2014-07-19 04:20:41 +08:00
TS_ASSERT_THROWS ( ws2 . get_named_range ( " wrong_sheet_range " ) , xlnt : : named_range_exception ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
2014-05-09 03:32:12 +08:00
void test_cell_alternate_coordinates ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2014-05-21 22:20:30 +08:00
auto cell = ws . get_cell ( xlnt : : cell_reference ( 4 , 8 ) ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( " D8 " , cell . get_reference ( ) . to_string ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
2014-05-09 03:32:12 +08:00
void test_cell_range_name ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
wb_ . create_named_range ( " test_range_single " , ws , " B12 " ) ;
2014-05-21 22:20:30 +08:00
auto c_range_name = ws . get_named_range ( " test_range_single " ) ;
auto c_range_coord = ws . get_range ( " B12 " ) ;
auto c_cell = ws . get_cell ( " B12 " ) ;
2014-05-13 01:42:28 +08:00
TS_ASSERT_EQUALS ( c_range_coord , c_range_name ) ;
2014-05-14 04:32:33 +08:00
TS_ASSERT ( c_range_coord [ 0 ] [ 0 ] = = c_cell ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
2014-05-09 03:32:12 +08:00
void test_garbage_collect ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
ws . get_cell ( " A1 " ) ;
2014-07-26 04:39:25 +08:00
ws . get_cell ( " B2 " ) . set_value ( " 0 " ) ;
ws . get_cell ( " C4 " ) . set_value ( 0 ) ;
2015-10-14 01:56:07 +08:00
xlnt : : comment ( ws . get_cell ( " D1 " ) , " Comment " , " Comment " ) ;
2014-05-13 01:42:28 +08:00
ws . garbage_collect ( ) ;
2015-10-14 01:56:07 +08:00
2014-07-25 05:31:46 +08:00
auto cell_collection = ws . get_cell_collection ( ) ;
std : : set < xlnt : : cell > cells ( cell_collection . begin ( ) , cell_collection . end ( ) ) ;
std : : set < xlnt : : cell > expected = { ws . get_cell ( " B2 " ) , ws . get_cell ( " C4 " ) , ws . get_cell ( " D1 " ) } ;
2015-10-14 01:56:07 +08:00
2014-07-25 05:31:46 +08:00
// Set difference
std : : set < xlnt : : cell > difference ;
2015-10-14 01:56:07 +08:00
2014-07-25 05:31:46 +08:00
for ( auto a : expected )
{
if ( cells . find ( a ) = = cells . end ( ) )
{
difference . insert ( a ) ;
}
}
2015-10-14 01:56:07 +08:00
2014-07-25 05:31:46 +08:00
for ( auto a : cells )
2014-05-13 01:42:28 +08:00
{
2014-07-25 05:31:46 +08:00
if ( expected . find ( a ) = = expected . end ( ) )
{
difference . insert ( a ) ;
}
2014-05-13 01:42:28 +08:00
}
2015-10-14 01:56:07 +08:00
2014-07-25 05:31:46 +08:00
TS_ASSERT ( difference . empty ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_hyperlink_value ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . get_cell ( " A1 " ) . set_hyperlink ( " http://test.com " ) ;
TS_ASSERT_EQUALS ( " http://test.com " , ws . get_cell ( " A1 " ) . get_value < std : : string > ( ) ) ;
ws . get_cell ( " A1 " ) . set_value ( " test " ) ;
TS_ASSERT_EQUALS ( " test " , ws . get_cell ( " A1 " ) . get_value < std : : string > ( ) ) ;
TS_ASSERT_EQUALS ( ws . get_cell ( " A1 " ) . get_hyperlink ( ) . get_target_uri ( ) , " http://test.com " ) ;
}
2014-05-09 03:32:12 +08:00
void test_hyperlink_relationships ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS ( ws . get_relationships ( ) . size ( ) , 0 ) ;
2015-10-14 01:56:07 +08:00
2014-06-11 05:12:15 +08:00
ws . get_cell ( " A1 " ) . set_hyperlink ( " http://test.com " ) ;
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS ( ws . get_relationships ( ) . size ( ) , 1 ) ;
2015-10-14 01:56:07 +08:00
2014-06-11 05:12:15 +08:00
ws . get_cell ( " A2 " ) . set_hyperlink ( " http://test2.com " ) ;
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS ( ws . get_relationships ( ) . size ( ) , 2 ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_append ( )
2014-05-09 03:32:12 +08:00
{
2015-10-14 01:56:07 +08:00
xlnt : : worksheet ws ( wb_ ) ;
ws . append ( std : : vector < std : : string > { " value " } ) ;
TS_ASSERT_EQUALS ( " value " , ws . get_cell ( " A1 " ) . get_value < std : : string > ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
2014-05-09 03:32:12 +08:00
void test_append_list ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
2014-05-14 02:40:28 +08:00
ws . append ( std : : vector < std : : string > { " This is A1 " , " This is B1 " } ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( " This is A1 " , ws . get_cell ( " A1 " ) . get_value < std : : string > ( ) ) ;
TS_ASSERT_EQUALS ( " This is B1 " , ws . get_cell ( " B1 " ) . get_value < std : : string > ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
2014-05-09 03:32:12 +08:00
void test_append_dict_letter ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
const std : : unordered_map < std : : string , std : : string > dict_letter =
{
{ " A " , " This is A1 " } ,
{ " C " , " This is C1 " }
} ;
ws . append ( dict_letter ) ;
TS_ASSERT_EQUALS ( " This is A1 " , ws . get_cell ( " A1 " ) . get_value < std : : string > ( ) ) ;
TS_ASSERT_EQUALS ( " This is C1 " , ws . get_cell ( " C1 " ) . get_value < std : : string > ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
2014-05-09 03:32:12 +08:00
void test_append_dict_index ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
const std : : unordered_map < int , std : : string > dict_index =
{
{ 1 , " This is A1 " } ,
{ 3 , " This is C1 " }
} ;
ws . append ( dict_index ) ;
TS_ASSERT_EQUALS ( " This is A1 " , ws . get_cell ( " A1 " ) . get_value < std : : string > ( ) ) ;
TS_ASSERT_EQUALS ( " This is C1 " , ws . get_cell ( " C1 " ) . get_value < std : : string > ( ) ) ;
}
void _test_bad_append ( )
{
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void _test_append_range ( )
{
2014-05-09 03:32:12 +08:00
2015-10-14 01:56:07 +08:00
}
void test_append_iterator ( )
{
std : : vector < int > range ;
for ( int i = 0 ; i < 30 ; i + + )
{
range . push_back ( i ) ;
}
xlnt : : worksheet ws ( wb_ ) ;
ws . append ( range . begin ( ) , range . end ( ) ) ;
TS_ASSERT_EQUALS ( ws [ xlnt : : cell_reference ( " AD1 " ) ] . get_value < int > ( ) , 29 ) ;
}
2014-05-09 03:32:12 +08:00
void test_append_2d_list ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
2014-05-14 02:40:28 +08:00
ws . append ( std : : vector < std : : string > { " This is A1 " , " This is B1 " } ) ;
ws . append ( std : : vector < std : : string > { " This is A2 " , " This is B2 " } ) ;
2015-10-14 01:56:07 +08:00
2014-05-21 22:20:30 +08:00
auto vals = ws . get_range ( " A1:B2 " ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( vals [ 0 ] [ 0 ] . get_value < std : : string > ( ) , " This is A1 " ) ;
TS_ASSERT_EQUALS ( vals [ 0 ] [ 1 ] . get_value < std : : string > ( ) , " This is B1 " ) ;
TS_ASSERT_EQUALS ( vals [ 1 ] [ 0 ] . get_value < std : : string > ( ) , " This is A2 " ) ;
TS_ASSERT_EQUALS ( vals [ 1 ] [ 1 ] . get_value < std : : string > ( ) , " This is B2 " ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void _test_append_cell ( )
{
// Right now, a cell cannot be created without a parent worksheet.
// This should be possible by instantiating a cell_impl, but the
// memory management is complicated.
/*
xlnt : : worksheet ws ( wb_ ) ;
xlnt : : cell cell ;
cell . set_value ( 25 ) ;
ws . append ( { cell } ) ;
TS_ASSERT_EQUALS ( cell . get_value < int > ( ) , 25 ) ;
*/
}
2014-05-09 03:32:12 +08:00
void test_rows ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
2014-07-26 04:39:25 +08:00
ws . get_cell ( " A1 " ) . set_value ( " first " ) ;
ws . get_cell ( " C9 " ) . set_value ( " last " ) ;
2015-10-14 01:56:07 +08:00
2014-05-14 02:40:28 +08:00
auto rows = ws . rows ( ) ;
2015-10-14 01:56:07 +08:00
2014-07-19 04:20:41 +08:00
TS_ASSERT_EQUALS ( rows . length ( ) , 9 ) ;
2015-10-14 01:56:07 +08:00
auto first_row = rows [ 0 ] ;
auto last_row = rows [ 8 ] ;
TS_ASSERT_EQUALS ( first_row [ 0 ] . get_value < std : : string > ( ) , " first " ) ;
TS_ASSERT_EQUALS ( first_row [ 0 ] . get_reference ( ) , " A1 " ) ;
TS_ASSERT_EQUALS ( last_row [ 2 ] . get_value < std : : string > ( ) , " last " ) ;
}
void test_no_cols ( )
{
xlnt : : worksheet ws ( wb_ ) ;
TS_ASSERT_EQUALS ( ws . columns ( ) . length ( ) , 1 ) ;
TS_ASSERT_EQUALS ( ws . columns ( ) [ 0 ] . length ( ) , 1 ) ;
2014-05-09 03:32:12 +08:00
}
2014-07-19 04:20:41 +08:00
void test_cols ( )
{
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
2014-07-26 04:39:25 +08:00
ws . get_cell ( " A1 " ) . set_value ( " first " ) ;
ws . get_cell ( " C9 " ) . set_value ( " last " ) ;
2015-10-14 01:56:07 +08:00
2014-07-19 04:20:41 +08:00
auto cols = ws . columns ( ) ;
2015-10-14 01:56:07 +08:00
2014-07-19 04:20:41 +08:00
TS_ASSERT_EQUALS ( cols . length ( ) , 3 ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( cols [ 0 ] [ 0 ] . get_value < std : : string > ( ) , " first " ) ;
TS_ASSERT_EQUALS ( cols [ 2 ] [ 8 ] . get_value < std : : string > ( ) , " last " ) ;
2014-07-19 04:20:41 +08:00
}
2015-10-14 01:56:07 +08:00
2014-05-09 03:32:12 +08:00
void test_auto_filter ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
2014-06-05 06:42:17 +08:00
ws . auto_filter ( ws . get_range ( " a1:f1 " ) ) ;
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS ( ws . get_auto_filter ( ) , " A1:F1 " ) ;
2015-10-14 01:56:07 +08:00
2014-05-19 09:29:19 +08:00
ws . unset_auto_filter ( ) ;
TS_ASSERT_EQUALS ( ws . has_auto_filter ( ) , false ) ;
2015-10-14 01:56:07 +08:00
2014-06-05 06:42:17 +08:00
ws . auto_filter ( " c1:g9 " ) ;
2014-05-19 09:29:19 +08:00
TS_ASSERT_EQUALS ( ws . get_auto_filter ( ) , " C1:G9 " ) ;
2014-05-09 03:32:12 +08:00
}
2014-07-27 04:19:15 +08:00
void test_getitem ( )
{
xlnt : : worksheet ws ( wb_ ) ;
xlnt : : cell cell = ws [ xlnt : : cell_reference ( " A1 " ) ] ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( cell . get_reference ( ) . to_string ( ) , " A1 " ) ;
TS_ASSERT_EQUALS ( cell . get_data_type ( ) , xlnt : : cell : : type : : null ) ;
2014-07-27 04:19:15 +08:00
}
void test_setitem ( )
{
xlnt : : worksheet ws ( wb_ ) ;
2015-10-02 06:14:42 +08:00
ws [ xlnt : : cell_reference ( " A1 " ) ] . set_value ( 5 ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT ( ws [ xlnt : : cell_reference ( " A1 " ) ] . get_value < int > ( ) = = 5 ) ;
2014-07-27 04:19:15 +08:00
}
void test_getslice ( )
{
xlnt : : worksheet ws ( wb_ ) ;
auto cell_range = ws ( " A1 " , " B2 " ) ;
TS_ASSERT_EQUALS ( cell_range [ 0 ] [ 0 ] , ws . get_cell ( " A1 " ) ) ;
TS_ASSERT_EQUALS ( cell_range [ 1 ] [ 0 ] , ws . get_cell ( " A2 " ) ) ;
TS_ASSERT_EQUALS ( cell_range [ 0 ] [ 1 ] , ws . get_cell ( " B1 " ) ) ;
TS_ASSERT_EQUALS ( cell_range [ 1 ] [ 1 ] , ws . get_cell ( " B2 " ) ) ;
}
2015-10-14 01:56:07 +08:00
2014-07-19 04:20:41 +08:00
void test_freeze ( )
2014-05-09 03:32:12 +08:00
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 01:56:07 +08:00
2014-07-19 04:20:41 +08:00
ws . freeze_panes ( ws . get_cell ( " b2 " ) ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( ws . get_frozen_panes ( ) , " B2 " ) ;
2014-07-19 04:20:41 +08:00
ws . unfreeze_panes ( ) ;
TS_ASSERT ( ! ws . has_frozen_panes ( ) ) ;
2015-10-14 01:56:07 +08:00
2014-07-19 04:20:41 +08:00
ws . freeze_panes ( " c5 " ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( ws . get_frozen_panes ( ) , " C5 " ) ;
2014-07-19 04:20:41 +08:00
ws . freeze_panes ( ws . get_cell ( " A1 " ) ) ;
TS_ASSERT ( ! ws . has_frozen_panes ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2015-10-14 01:56:07 +08:00
void test_merged_cells_lookup ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . merge_cells ( " A1:N50 " ) ;
auto all_merged = ws . get_merged_ranges ( ) ;
TS_ASSERT_EQUALS ( all_merged . size ( ) , 1 ) ;
auto merged = ws . get_range ( all_merged [ 0 ] ) ;
TS_ASSERT ( merged . contains ( " A1 " ) ) ;
TS_ASSERT ( merged . contains ( " N50 " ) ) ;
TS_ASSERT ( ! merged . contains ( " A51 " ) ) ;
TS_ASSERT ( ! merged . contains ( " O1 " ) ) ;
}
void test_merged_cell_ranges ( )
{
xlnt : : worksheet ws ( wb_ ) ;
TS_ASSERT_EQUALS ( ws . get_merged_ranges ( ) . size ( ) , 0 ) ;
}
void test_merge_range_string ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . get_cell ( " A1 " ) . set_value ( 1 ) ;
ws . get_cell ( " D4 " ) . set_value ( 16 ) ;
ws . merge_cells ( " A1:D4 " ) ;
std : : vector < xlnt : : range_reference > expected = { xlnt : : range_reference ( " A1:D4 " ) } ;
TS_ASSERT_EQUALS ( ws . get_merged_ranges ( ) , expected ) ;
TS_ASSERT ( ! ws . get_cell ( " D4 " ) . has_value ( ) ) ;
}
void test_merge_coordinate ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . merge_cells ( 1 , 1 , 4 , 4 ) ;
std : : vector < xlnt : : range_reference > expected = { xlnt : : range_reference ( " A1:D4 " ) } ;
TS_ASSERT_EQUALS ( ws . get_merged_ranges ( ) , expected ) ;
}
void test_unmerge_range_string ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . merge_cells ( " A1:D4 " ) ;
TS_ASSERT_EQUALS ( ws . get_merged_ranges ( ) . size ( ) , 1 ) ;
ws . unmerge_cells ( " A1:D4 " ) ;
TS_ASSERT_EQUALS ( ws . get_merged_ranges ( ) . size ( ) , 0 ) ;
}
void test_unmerge_coordinate ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . merge_cells ( " A1:D4 " ) ;
TS_ASSERT_EQUALS ( ws . get_merged_ranges ( ) . size ( ) , 1 ) ;
ws . unmerge_cells ( 1 , 1 , 4 , 4 ) ;
TS_ASSERT_EQUALS ( ws . get_merged_ranges ( ) . size ( ) , 0 ) ;
}
void test_print_titles ( )
{
xlnt : : worksheet ws ( wb_ ) ;
}
void test_positioning_point ( )
{
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 04:35:22 +08:00
TS_ASSERT_EQUALS ( ws . get_point_pos ( 150 , 40 ) , " C3 " ) ;
2015-10-14 01:56:07 +08:00
}
void test_positioning_roundtrip ( )
{
xlnt : : worksheet ws ( wb_ ) ;
TS_ASSERT_EQUALS ( ws . get_point_pos ( ws . get_cell ( " A1 " ) . get_anchor ( ) ) , xlnt : : cell_reference ( " A1 " ) ) ;
TS_ASSERT_EQUALS ( ws . get_point_pos ( ws . get_cell ( " D52 " ) . get_anchor ( ) ) , xlnt : : cell_reference ( " D52 " ) ) ;
TS_ASSERT_EQUALS ( ws . get_point_pos ( ws . get_cell ( " X11 " ) . get_anchor ( ) ) , xlnt : : cell_reference ( " X11 " ) ) ;
}
void test_freeze_panes_horiz ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . freeze_panes ( " A4 " ) ;
}
void test_freeze_panes_vert ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . freeze_panes ( " D1 " ) ;
}
void test_freeze_panes_both ( )
{
xlnt : : worksheet ws ( wb_ ) ;
ws . freeze_panes ( " D4 " ) ;
}
void test_min_column ( )
{
xlnt : : worksheet ws ( wb_ ) ;
TS_ASSERT_EQUALS ( ws . get_lowest_column ( ) , 1 ) ;
}
void test_max_column ( )
{
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 04:35:22 +08:00
ws [ xlnt : : cell_reference ( " F1 " ) ] . set_value ( 10 ) ;
ws [ xlnt : : cell_reference ( " F2 " ) ] . set_value ( 32 ) ;
ws [ xlnt : : cell_reference ( " F3 " ) ] . set_formula ( " =F1+F2 " ) ;
ws [ xlnt : : cell_reference ( " A4 " ) ] . set_formula ( " =A1+A2+A3 " ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( ws . get_highest_column ( ) , 6 ) ;
}
void test_min_row ( )
{
xlnt : : worksheet ws ( wb_ ) ;
TS_ASSERT_EQUALS ( ws . get_lowest_row ( ) , 1 ) ;
}
void test_max_row ( )
{
xlnt : : worksheet ws ( wb_ ) ;
2015-10-14 04:35:22 +08:00
ws . append ( ) ;
ws . append ( std : : vector < int > { 5 } ) ;
ws . append ( ) ;
ws . append ( std : : vector < int > { 4 } ) ;
2015-10-14 01:56:07 +08:00
TS_ASSERT_EQUALS ( ws . get_highest_row ( ) , 4 ) ;
}
// end 2.4 synchronized tests
void test_new_sheet_name ( )
{
xlnt : : worksheet ws = wb_ . create_sheet ( " TestName " ) ;
TS_ASSERT_EQUALS ( ws . to_string ( ) , " <Worksheet \" TestName \" > " ) ;
}
void test_set_bad_title ( )
{
std : : string title ( 50 , ' X ' ) ;
TS_ASSERT_THROWS ( wb_ . create_sheet ( title ) , xlnt : : sheet_title_exception ) ;
}
void test_increment_title ( )
{
auto ws1 = wb_ . create_sheet ( " Test " ) ;
TS_ASSERT_EQUALS ( ws1 . get_title ( ) , " Test " ) ;
auto ws2 = wb_ . create_sheet ( " Test " ) ;
TS_ASSERT_EQUALS ( ws2 . get_title ( ) , " Test1 " ) ;
}
void test_set_bad_title_character ( )
{
TS_ASSERT_THROWS ( wb_ . create_sheet ( " [ " ) , xlnt : : sheet_title_exception ) ;
TS_ASSERT_THROWS ( wb_ . create_sheet ( " ] " ) , xlnt : : sheet_title_exception ) ;
TS_ASSERT_THROWS ( wb_ . create_sheet ( " * " ) , xlnt : : sheet_title_exception ) ;
TS_ASSERT_THROWS ( wb_ . create_sheet ( " : " ) , xlnt : : sheet_title_exception ) ;
TS_ASSERT_THROWS ( wb_ . create_sheet ( " ? " ) , xlnt : : sheet_title_exception ) ;
TS_ASSERT_THROWS ( wb_ . create_sheet ( " / " ) , xlnt : : sheet_title_exception ) ;
TS_ASSERT_THROWS ( wb_ . create_sheet ( " \\ " ) , xlnt : : sheet_title_exception ) ;
}
void test_unique_sheet_title ( )
{
auto ws = wb_ . create_sheet ( " AGE " ) ;
TS_ASSERT_EQUALS ( ws . unique_sheet_name ( " GE " ) , " GE " ) ;
}
void test_worksheet_range ( )
{
xlnt : : worksheet ws ( wb_ ) ;
auto xlrange = ws . get_range ( " A1:C4 " ) ;
TS_ASSERT_EQUALS ( 4 , xlrange . length ( ) ) ;
TS_ASSERT_EQUALS ( 3 , xlrange [ 0 ] . num_cells ( ) ) ;
}
void test_cell_offset ( )
{
xlnt : : worksheet ws ( wb_ ) ;
TS_ASSERT_EQUALS ( " C17 " , ws . get_cell ( xlnt : : cell_reference ( " B15 " ) . make_offset ( 1 , 2 ) ) . get_reference ( ) . to_string ( ) ) ;
}
void test_range_offset ( )
{
xlnt : : worksheet ws ( wb_ ) ;
auto xlrange = ws . get_range ( xlnt : : range_reference ( " A1:C4 " ) . make_offset ( 3 , 1 ) ) ;
TS_ASSERT_EQUALS ( 4 , xlrange . length ( ) ) ;
TS_ASSERT_EQUALS ( 3 , xlrange [ 0 ] . num_cells ( ) ) ;
TS_ASSERT_EQUALS ( " D2 " , xlrange [ 0 ] [ 0 ] . get_reference ( ) . to_string ( ) ) ;
}
void test_bad_relationship_type ( )
{
xlnt : : relationship rel ( " bad " ) ;
}
2014-05-09 03:32:12 +08:00
2014-07-19 04:20:41 +08:00
void test_write_empty ( )
2014-05-09 03:32:12 +08:00
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2014-07-19 04:20:41 +08:00
2015-10-15 06:05:13 +08:00
auto xml_string = xlnt : : write_worksheet ( ws ) ;
2014-05-14 02:40:28 +08:00
2014-05-19 09:29:19 +08:00
pugi : : xml_document doc ;
doc . load ( xml_string . c_str ( ) ) ;
2014-07-26 04:39:25 +08:00
auto expected_string =
" <worksheet xmlns= \" http://schemas.openxmlformats.org/spreadsheetml/2006/main \" xmlns:r= \" http://schemas.openxmlformats.org/officeDocument/2006/relationships \" > "
" <sheetPr> "
" <outlinePr summaryRight= \" 1 \" summaryBelow= \" 1 \" /> "
" </sheetPr> "
" <dimension ref= \" A1:A1 \" /> "
" <sheetViews> "
" <sheetView workbookViewId= \" 0 \" > "
" <selection sqref= \" A1 \" activeCell= \" A1 \" /> "
" </sheetView> "
" </sheetViews> "
" <sheetFormatPr baseColWidth= \" 10 \" defaultRowHeight= \" 15 \" /> "
" <sheetData/> "
" <pageMargins left= \" 0.75 \" right= \" 0.75 \" top= \" 1 \" bottom= \" 1 \" header= \" 0.5 \" footer= \" 0.5 \" /> "
" </worksheet> " ;
pugi : : xml_document expected_doc ;
expected_doc . load ( expected_string ) ;
TS_ASSERT ( Helper : : compare_xml ( expected_doc , doc ) ) ;
2014-05-09 03:32:12 +08:00
}
2014-07-19 04:20:41 +08:00
void test_page_margins ( )
2014-05-09 03:32:12 +08:00
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2014-07-26 04:39:25 +08:00
ws . get_page_margins ( ) . set_left ( 2 ) ;
ws . get_page_margins ( ) . set_right ( 2 ) ;
ws . get_page_margins ( ) . set_top ( 2 ) ;
ws . get_page_margins ( ) . set_bottom ( 2 ) ;
ws . get_page_margins ( ) . set_header ( 1.5 ) ;
ws . get_page_margins ( ) . set_footer ( 1.5 ) ;
2014-07-19 04:20:41 +08:00
2015-10-15 06:05:13 +08:00
auto xml_string = xlnt : : write_worksheet ( ws ) ;
2014-05-09 03:32:12 +08:00
2014-07-19 04:20:41 +08:00
pugi : : xml_document doc ;
doc . load ( xml_string . c_str ( ) ) ;
2014-07-26 04:39:25 +08:00
auto expected_string =
" <worksheet xmlns= \" http://schemas.openxmlformats.org/spreadsheetml/2006/main \" xmlns:r= \" http://schemas.openxmlformats.org/officeDocument/2006/relationships \" > "
" <sheetPr> "
" <outlinePr summaryRight= \" 1 \" summaryBelow= \" 1 \" /> "
" </sheetPr> "
" <dimension ref= \" A1:A1 \" /> "
" <sheetViews> "
" <sheetView workbookViewId= \" 0 \" > "
" <selection sqref= \" A1 \" activeCell= \" A1 \" /> "
" </sheetView> "
" </sheetViews> "
" <sheetFormatPr baseColWidth= \" 10 \" defaultRowHeight= \" 15 \" /> "
" <sheetData/> "
" <pageMargins left= \" 2 \" right= \" 2 \" top= \" 2 \" bottom= \" 2 \" header= \" 1.5 \" footer= \" 1.5 \" /> "
" </worksheet> " ;
pugi : : xml_document expected_doc ;
expected_doc . load ( expected_string ) ;
TS_ASSERT ( Helper : : compare_xml ( expected_doc , doc ) ) ;
2014-07-19 04:20:41 +08:00
}
void test_merge ( )
{
xlnt : : worksheet ws ( wb_ ) ;
2014-07-26 04:39:25 +08:00
std : : vector < std : : string > string_table = { " Cell A1 " , " Cell B1 " } ;
2014-07-19 04:20:41 +08:00
2014-07-26 04:39:25 +08:00
auto expected_string1 =
" <worksheet xmlns= \" http://schemas.openxmlformats.org/spreadsheetml/2006/main \" xmlns:r= \" http://schemas.openxmlformats.org/officeDocument/2006/relationships \" > "
" <sheetPr> "
" <outlinePr summaryRight= \" 1 \" summaryBelow= \" 1 \" /> "
" </sheetPr> "
" <dimension ref= \" A1:B1 \" /> "
" <sheetViews> "
" <sheetView workbookViewId= \" 0 \" > "
" <selection sqref= \" A1 \" activeCell= \" A1 \" /> "
" </sheetView> "
" </sheetViews> "
" <sheetFormatPr baseColWidth= \" 10 \" defaultRowHeight= \" 15 \" /> "
" <sheetData> "
" <row r= \" 1 \" spans= \" 1:2 \" > "
" <c r= \" A1 \" t= \" s \" > "
" <v>0</v> "
" </c> "
" <c r= \" B1 \" t= \" s \" > "
" <v>1</v> "
" </c> "
" </row> "
" </sheetData> "
" <pageMargins left= \" 0.75 \" right= \" 0.75 \" top= \" 1 \" bottom= \" 1 \" header= \" 0.5 \" footer= \" 0.5 \" /> "
" </worksheet> " ;
ws . get_cell ( " A1 " ) . set_value ( " Cell A1 " ) ;
ws . get_cell ( " B1 " ) . set_value ( " Cell B1 " ) ;
2015-10-15 06:05:13 +08:00
auto xml_string = xlnt : : write_worksheet ( ws , string_table ) ;
2014-05-14 02:40:28 +08:00
2014-07-19 04:20:41 +08:00
pugi : : xml_document doc ;
doc . load ( xml_string . c_str ( ) ) ;
2014-07-26 04:39:25 +08:00
pugi : : xml_document expected_doc ;
expected_doc . load ( expected_string1 ) ;
TS_ASSERT ( Helper : : compare_xml ( expected_doc , doc ) ) ;
ws . merge_cells ( " A1:B1 " ) ;
2015-10-15 06:05:13 +08:00
xml_string = xlnt : : write_worksheet ( ws , string_table ) ;
2014-07-26 04:39:25 +08:00
auto expected_string2 =
" <worksheet xmlns= \" http://schemas.openxmlformats.org/spreadsheetml/2006/main \" xmlns:r= \" http://schemas.openxmlformats.org/officeDocument/2006/relationships \" > "
" <sheetPr> "
" <outlinePr summaryRight= \" 1 \" summaryBelow= \" 1 \" /> "
" </sheetPr> "
" <dimension ref= \" A1:B1 \" /> "
" <sheetViews> "
" <sheetView workbookViewId= \" 0 \" > "
" <selection sqref= \" A1 \" activeCell= \" A1 \" /> "
" </sheetView> "
" </sheetViews> "
" <sheetFormatPr baseColWidth= \" 10 \" defaultRowHeight= \" 15 \" /> "
" <sheetData> "
" <row r= \" 1 \" spans= \" 1:2 \" > "
" <c r= \" A1 \" t= \" s \" > "
" <v>0</v> "
" </c> "
" <c r= \" B1 \" t= \" s \" /> "
" </row> "
" </sheetData> "
" <mergeCells count= \" 1 \" > "
" <mergeCell ref= \" A1:B1 \" /> "
" </mergeCells> "
" <pageMargins left= \" 0.75 \" right= \" 0.75 \" top= \" 1 \" bottom= \" 1 \" header= \" 0.5 \" footer= \" 0.5 \" /> "
" </worksheet> " ;
doc . load ( xml_string . c_str ( ) ) ;
expected_doc . load ( expected_string2 ) ;
TS_ASSERT ( Helper : : compare_xml ( expected_doc , doc ) ) ;
ws . unmerge_cells ( " A1:B1 " ) ;
2015-10-15 06:05:13 +08:00
xml_string = xlnt : : write_worksheet ( ws , string_table ) ;
2014-07-26 04:39:25 +08:00
auto expected_string3 =
" <worksheet xmlns= \" http://schemas.openxmlformats.org/spreadsheetml/2006/main \" xmlns:r= \" http://schemas.openxmlformats.org/officeDocument/2006/relationships \" > "
" <sheetPr> "
" <outlinePr summaryRight= \" 1 \" summaryBelow= \" 1 \" /> "
" </sheetPr> "
" <dimension ref= \" A1:B1 \" /> "
" <sheetViews> "
" <sheetView workbookViewId= \" 0 \" > "
" <selection sqref= \" A1 \" activeCell= \" A1 \" /> "
" </sheetView> "
" </sheetViews> "
" <sheetFormatPr baseColWidth= \" 10 \" defaultRowHeight= \" 15 \" /> "
" <sheetData> "
" <row r= \" 1 \" spans= \" 1:2 \" > "
" <c r= \" A1 \" t= \" s \" > "
" <v>0</v> "
" </c> "
" <c r= \" B1 \" t= \" s \" /> "
" </row> "
" </sheetData> "
" <pageMargins left= \" 0.75 \" right= \" 0.75 \" top= \" 1 \" bottom= \" 1 \" header= \" 0.5 \" footer= \" 0.5 \" /> "
" </worksheet> " ;
doc . load ( xml_string . c_str ( ) ) ;
expected_doc . load ( expected_string3 ) ;
TS_ASSERT ( Helper : : compare_xml ( expected_doc , doc ) ) ;
2014-05-09 03:32:12 +08:00
}
void test_printer_settings ( )
{
2014-06-16 00:16:34 +08:00
xlnt : : worksheet ws ( wb_ ) ;
2014-05-14 02:40:28 +08:00
2014-05-20 08:47:15 +08:00
ws . get_page_setup ( ) . set_orientation ( xlnt : : page_setup : : orientation : : landscape ) ;
2014-05-21 22:20:30 +08:00
ws . get_page_setup ( ) . set_paper_size ( xlnt : : page_setup : : paper_size : : tabloid ) ;
2014-05-20 08:47:15 +08:00
ws . get_page_setup ( ) . set_fit_to_page ( true ) ;
ws . get_page_setup ( ) . set_fit_to_height ( false ) ;
ws . get_page_setup ( ) . set_fit_to_width ( true ) ;
2014-08-02 04:46:54 +08:00
ws . get_page_setup ( ) . set_horizontal_centered ( true ) ;
ws . get_page_setup ( ) . set_vertical_centered ( true ) ;
2014-05-20 08:47:15 +08:00
2015-10-15 06:05:13 +08:00
auto xml_string = xlnt : : write_worksheet ( ws ) ;
2014-05-20 08:47:15 +08:00
2014-05-19 09:29:19 +08:00
pugi : : xml_document doc ;
doc . load ( xml_string . c_str ( ) ) ;
2014-07-27 04:19:15 +08:00
auto expected_string =
" <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> "
" <worksheet xmlns= \" http://schemas.openxmlformats.org/spreadsheetml/2006/main \" xmlns:r= \" http://schemas.openxmlformats.org/officeDocument/2006/relationships \" > "
" <sheetPr> "
" <outlinePr summaryRight= \" 1 \" summaryBelow= \" 1 \" /> "
" <pageSetUpPr fitToPage= \" 1 \" /> "
" </sheetPr> "
" <dimension ref= \" A1:A1 \" /> "
" <sheetViews> "
" <sheetView workbookViewId= \" 0 \" > "
" <selection sqref= \" A1 \" activeCell= \" A1 \" /> "
" </sheetView> "
" </sheetViews> "
" <sheetFormatPr baseColWidth= \" 10 \" defaultRowHeight= \" 15 \" /> "
" <sheetData /> "
" <printOptions horizontalCentered= \" 1 \" verticalCentered= \" 1 \" /> "
" <pageMargins left= \" 0.75 \" right= \" 0.75 \" top= \" 1 \" bottom= \" 1 \" header= \" 0.5 \" footer= \" 0.5 \" /> "
" <pageSetup orientation= \" landscape \" paperSize= \" 3 \" fitToHeight= \" 0 \" fitToWidth= \" 1 \" /> "
" </worksheet> " ;
pugi : : xml_document expected_doc ;
expected_doc . load ( expected_string ) ;
2014-05-20 08:47:15 +08:00
2014-07-27 04:19:15 +08:00
TS_ASSERT ( Helper : : compare_xml ( expected_doc , doc ) ) ;
2014-07-19 04:20:41 +08:00
}
void test_header_footer ( )
{
auto ws = wb_ . create_sheet ( ) ;
ws . get_header_footer ( ) . get_left_header ( ) . set_text ( " Left Header Text " ) ;
ws . get_header_footer ( ) . get_center_header ( ) . set_text ( " Center Header Text " ) ;
ws . get_header_footer ( ) . get_center_header ( ) . set_font_name ( " Arial,Regular " ) ;
ws . get_header_footer ( ) . get_center_header ( ) . set_font_size ( 6 ) ;
ws . get_header_footer ( ) . get_center_header ( ) . set_font_color ( " 445566 " ) ;
ws . get_header_footer ( ) . get_right_header ( ) . set_text ( " Right Header Text " ) ;
ws . get_header_footer ( ) . get_right_header ( ) . set_font_name ( " Arial,Bold " ) ;
ws . get_header_footer ( ) . get_right_header ( ) . set_font_size ( 8 ) ;
ws . get_header_footer ( ) . get_right_header ( ) . set_font_color ( " 112233 " ) ;
ws . get_header_footer ( ) . get_left_footer ( ) . set_text ( " Left Footer Text \n And &[Date] and &[Time] " ) ;
ws . get_header_footer ( ) . get_left_footer ( ) . set_font_name ( " Times New Roman,Regular " ) ;
ws . get_header_footer ( ) . get_left_footer ( ) . set_font_size ( 10 ) ;
ws . get_header_footer ( ) . get_left_footer ( ) . set_font_color ( " 445566 " ) ;
ws . get_header_footer ( ) . get_center_footer ( ) . set_text ( " Center Footer Text &[Path]&[File] on &[Tab] " ) ;
ws . get_header_footer ( ) . get_center_footer ( ) . set_font_name ( " Times New Roman,Bold " ) ;
ws . get_header_footer ( ) . get_center_footer ( ) . set_font_size ( 12 ) ;
ws . get_header_footer ( ) . get_center_footer ( ) . set_font_color ( " 778899 " ) ;
ws . get_header_footer ( ) . get_right_footer ( ) . set_text ( " Right Footer Text &[Page] of &[Pages] " ) ;
ws . get_header_footer ( ) . get_right_footer ( ) . set_font_name ( " Times New Roman,Italic " ) ;
ws . get_header_footer ( ) . get_right_footer ( ) . set_font_size ( 14 ) ;
ws . get_header_footer ( ) . get_right_footer ( ) . set_font_color ( " AABBCC " ) ;
2014-07-20 04:59:05 +08:00
std : : string expected_xml_string =
2014-07-19 04:20:41 +08:00
" <worksheet xmlns= \" http://schemas.openxmlformats.org/spreadsheetml/2006/main \" xmlns:r= \" http://schemas.openxmlformats.org/officeDocument/2006/relationships \" > "
" <sheetPr> "
" <outlinePr summaryRight= \" 1 \" summaryBelow= \" 1 \" /> "
" </sheetPr> "
" <dimension ref= \" A1:A1 \" /> "
" <sheetViews> "
" <sheetView workbookViewId= \" 0 \" > "
" <selection sqref= \" A1 \" activeCell= \" A1 \" /> "
" </sheetView> "
" </sheetViews> "
" <sheetFormatPr baseColWidth= \" 10 \" defaultRowHeight= \" 15 \" /> "
" <sheetData/> "
" <pageMargins left= \" 0.75 \" right= \" 0.75 \" top= \" 1 \" bottom= \" 1 \" header= \" 0.5 \" footer= \" 0.5 \" /> "
" <headerFooter> "
" <oddHeader>&L& \" Calibri,Regular \" &K000000Left Header Text&C& \" Arial,Regular \" &6&K445566Center Header Text&R& \" Arial,Bold \" &8&K112233Right Header Text</oddHeader> "
" <oddFooter>&L& \" Times New Roman,Regular \" &10&K445566Left Footer Text_x000D_And &D and &T&C& \" Times New Roman,Bold \" &12&K778899Center Footer Text &Z&F on &A&R& \" Times New Roman,Italic \" &14&KAABBCCRight Footer Text &P of &N</oddFooter> "
" </headerFooter> "
" </worksheet> " ;
2014-07-20 04:59:05 +08:00
pugi : : xml_document expected_doc ;
pugi : : xml_document observed_doc ;
2014-07-19 04:20:41 +08:00
2014-07-20 04:59:05 +08:00
expected_doc . load ( expected_xml_string . c_str ( ) ) ;
2015-10-15 06:05:13 +08:00
observed_doc . load ( xlnt : : write_worksheet ( ws , { } , { } ) . c_str ( ) ) ;
2014-07-19 04:20:41 +08:00
2014-07-20 04:59:05 +08:00
TS_ASSERT ( Helper : : compare_xml ( expected_doc , observed_doc ) ) ;
2014-07-19 04:20:41 +08:00
2014-07-20 04:59:05 +08:00
ws = wb_ . create_sheet ( ) ;
2014-07-19 04:20:41 +08:00
expected_xml_string =
" <worksheet xmlns= \" http://schemas.openxmlformats.org/spreadsheetml/2006/main \" xmlns:r= \" http://schemas.openxmlformats.org/officeDocument/2006/relationships \" > "
" <sheetPr> "
2014-07-20 04:59:05 +08:00
" <outlinePr summaryRight= \" 1 \" summaryBelow= \" 1 \" /> "
2014-07-19 04:20:41 +08:00
" </sheetPr> "
2014-07-20 04:59:05 +08:00
" <dimension ref= \" A1:A1 \" /> "
2014-07-19 04:20:41 +08:00
" <sheetViews> "
2014-07-20 04:59:05 +08:00
" <sheetView workbookViewId= \" 0 \" > "
" <selection sqref= \" A1 \" activeCell= \" A1 \" /> "
2014-07-19 04:20:41 +08:00
" </sheetView> "
" </sheetViews> "
2014-07-20 04:59:05 +08:00
" <sheetFormatPr baseColWidth= \" 10 \" defaultRowHeight= \" 15 \" /> "
2014-07-19 04:20:41 +08:00
" <sheetData/> "
2014-07-20 04:59:05 +08:00
" <pageMargins left= \" 0.75 \" right= \" 0.75 \" top= \" 1 \" bottom= \" 1 \" header= \" 0.5 \" footer= \" 0.5 \" /> "
2014-07-19 04:20:41 +08:00
" </worksheet> " ;
2014-07-20 04:59:05 +08:00
expected_doc . load ( expected_xml_string . c_str ( ) ) ;
2015-10-15 06:05:13 +08:00
observed_doc . load ( xlnt : : write_worksheet ( ws , { } , { } ) . c_str ( ) ) ;
2014-07-19 04:20:41 +08:00
2014-07-20 04:59:05 +08:00
TS_ASSERT ( Helper : : compare_xml ( expected_doc , observed_doc ) ) ;
2014-07-19 04:20:41 +08:00
}
void test_page_setup ( )
{
xlnt : : page_setup p ;
2014-07-26 04:39:25 +08:00
TS_ASSERT_EQUALS ( p . get_scale ( ) , 1 ) ;
p . set_scale ( 2 ) ;
TS_ASSERT_EQUALS ( p . get_scale ( ) , 2 ) ;
2014-07-19 04:20:41 +08:00
}
void test_page_options ( )
{
xlnt : : page_setup p ;
2014-07-26 04:39:25 +08:00
TS_ASSERT ( ! p . get_horizontal_centered ( ) ) ;
TS_ASSERT ( ! p . get_vertical_centered ( ) ) ;
2014-07-19 04:20:41 +08:00
p . set_horizontal_centered ( true ) ;
p . set_vertical_centered ( true ) ;
2014-07-26 04:39:25 +08:00
TS_ASSERT ( p . get_horizontal_centered ( ) ) ;
TS_ASSERT ( p . get_vertical_centered ( ) ) ;
2014-05-09 03:32:12 +08:00
}
2014-05-14 02:40:28 +08:00
private :
2014-06-16 00:16:34 +08:00
xlnt : : workbook wb_ ;
2014-05-09 03:32:12 +08:00
} ;