Google-RestApi

 view release on metacpan or  search on metacpan

lib/Google/RestApi/SheetsApi4/Range.pm  view on Meta::CPAN

# - - Fred
# if a range is included it's a flag that the dim and values are present from
# the returned api call.
sub _cache_range_values {
  my $self = shift;

  my %p = @_;
  # if a range is included, assume this cache is coming from the api as a reply.
  # this is to store the values for this range when includeValuesInResponse is
  # added to the url or content on the original values call. you can replace the
  # original values using the valueRenderOption to replace, say, formulas with their
  # calculated value.
  if ($p{range}) {
    state $check = compile_named(
      majorDimension => DimColRow,
      range          => StrMatch[qr/.+!/],
      values         => ArrayRef, { optional => 1 }  # will not exist if values aren't set in the ss.
    );
    my $p = $check->(@_);

    # remove all quotes for comparison.

lib/Google/RestApi/SheetsApi4/Request.pm  view on Meta::CPAN


A Request is a lightweight object that is used to collect and then
submit a number of batch requests such as formatting, spreadsheet
properties, worksheet properties etc.

Other classes in this api derive from this object and its child
objects. You would not normally have to interact with this object
directly as it is already built in to the other classes in this
api. It is documented here for background understanding.

Batch requests are formulated and queued up to be submitted later
via 'submit_requests'. This class hierarchy encapsulates the
tedious work of constructing the complex, deep hashes required for
cell formatting or setting various properties.

 Spreadsheet: Derives from Request::Spreadsheet.
 Worksheet: Derives from Request::Spreadsheet::Worksheet.
 Range: Derives from Request::Spreadsheet::Worksheet::Range.

A Spreadsheet object can only submit requests that have to do with
spreadsheets. A Worksheet object can submit requests that have to

t/integration/Google/RestApi/SheetsApi4/Range.t  view on Meta::CPAN

# use Carp::Always;
# init_logger($DEBUG);

delete_all_spreadsheets(sheets_api());

my $spreadsheet = spreadsheet();
my $ws0 = $spreadsheet->open_worksheet(id => 0);

clear();
named();
formulas();
requests();

sub clear {
  my $range = $ws0->range("A1:Z99");
  is_hash sub { $range->clear(); }, "Clearing a range";
  return;
}

sub named {
  my @values = (

t/integration/Google/RestApi/SheetsApi4/Range.t  view on Meta::CPAN

  like $range->range(), qr/'$name'!$row$/, "Normalized range should be $row";

  my $named_group = $spreadsheet->range_group(
    map { $ws0->range_factory($_); } qw(xxx col_named_range row_named_range)
  );
  is_hash $named_group->delete_named()->submit_requests(), "Delete of named ranges";

  return;
}

sub formulas {
  my $sum = '=SUM(A1:B1)';
  my @values = (1, 1, $sum);
  my $range = $ws0->range_row("A1:C1");
  $range->values(values => \@values);

  is $ws0->range_cell('C1')->values(), 2, "Returned formula value should be 2";
  is $ws0->range_cell('C1')->values(
    params => {
      valueRenderOption => 'FORMULA',
    }
  ), $sum, "Returned formula value should be '$sum'";

  is_array $range->values(
    values => \@values,
    params => {
      includeValuesInResponse => 'true',
    },
  ), "Returning values in response";

  is $range->values()->[2], 2, "Returned formula value should be 2";

  is_array $range->values(
    values => \@values,
    params => {
      includeValuesInResponse   => 'true',
      responseValueRenderOption => 'FORMULA',
    },
  ), "Returning values in response";
  is $range->values()->[2], $sum, "Returned formula value should be '$sum'";

  is_hash $range->batch_values(values => \@values), "Returning batch values";
  is_array $range->submit_values(
    content => { includeValuesInResponse   => 'true' },
  ),"Submitting batch values in response";
  is $range->values()->[2], 2, "Returned batch formula value should be 2";

  is_hash $range->batch_values(values => \@values), "Returning batch values";
  is_array $range->submit_values(
    content => {
      includeValuesInResponse   => 'true',
      responseValueRenderOption => 'FORMULA',
    },
  ), "Returning batch values in response";
  is $range->values()->[2], $sum, "Returned batch formula value should be '$sum'";

  return;
}

sub requests {
  my $range = $ws0->range("A1:B2");
  isa_ok $range->
       bold()->bold(0)->red()->bk_blue(0.5)->merge_both()->
       bd_blue('top')->bd_red(0.3, 'bottom')->bd_green(0, 'left')->
       bd_dashed()->bd_dashed('inner')->bd_repeat_cell()->bd_red('bottom')->bd_dashed(),

t/tutorial/sheets/20_worksheet.pl  view on Meta::CPAN

end("'Payroll' worksheet headings should now be formatted.");

# a column could start at the second row and still be called a column.
start("Now we will bold the IDs column.");
$ws0->range_col("A2:A")->bold()->submit_requests();
end("IDs should now be bolded.");

# do a batch update and formatting request via a range group.
# range groups can be used to format each range in the range group.
# ranges can be specified in very flexible ways.
start("Now we will set a couple of formulas via batch.");
my $tax = $ws0->range_cell([ 3, 5 ]);                    # same as "C5"
my $salary = $ws0->range_cell({ row => 5, col => "D" }); # same as "D5"
$tax->batch_values(values => "=SUM(C2:C4)");
$salary->batch_values(values => "=SUM(D2:D4)");
my $rg = $ss->range_group($tax, $salary);
$rg->submit_values();
$rg->bold()->italic()->bd_solid()->bd_thick('bottom')->submit_requests();
end("Totals should now be set with formulas.");

message('green', "\nProceed to 25_worksheet.pl.\n");

message('blue', "We are done, here are some api stats:\n", Dump($ss->stats()));



( run in 0.281 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )