Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore contents in <rPh> and <phoneticPr> #72 #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 60 additions & 55 deletions lib/Spreadsheet/ParseXLSX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -505,69 +505,74 @@ sub _get_text_and_rich_font_by_cell {

my $string_text = '';
my @rich_font_by_cell;
my @nodes_r = $si->find_nodes('.//s:r');
if (@nodes_r > 0) {
for my $chunk (map { $_->children } @nodes_r) {
my $string_length = length($string_text);
if ($chunk->name eq 's:t') {
if (!@rich_font_by_cell) {
push @rich_font_by_cell, [
$string_length,
Spreadsheet::ParseExcel::Font->new(%default_font_opts)
];
}
$string_text .= $chunk->text;
}
elsif ($chunk->name eq 's:rPr') {
my %format_text = %default_font_opts;
for my $node_format ($chunk->children) {
if ($node_format->name eq 's:sz') {
$format_text{Height} = $node_format->att('val');
}
elsif ($node_format->name eq 's:color') {
$format_text{Color} = $self->_color(
$theme_colors,
$node_format
);
}
elsif ($node_format->name eq 's:rFont') {
$format_text{Name} = $node_format->att('val');
}
elsif ($node_format->name eq 's:b') {
$format_text{Bold} = 1;
}
elsif ($node_format->name eq 's:i') {
$format_text{Italic} = 1;
for my $subnode ($si->children) {
if ($subnode->name eq 's:t') {
$string_text .= $subnode->text;
}
elsif ($subnode->name eq 's:r') {
for my $chunk ($subnode->children) {
my $string_length = length($string_text);
if ($chunk->name eq 's:t') {
if (!@rich_font_by_cell) {
push @rich_font_by_cell, [
$string_length,
Spreadsheet::ParseExcel::Font->new(%default_font_opts)
];
}
elsif ($node_format->name eq 's:u') {
$format_text{Underline} = 1;
if (defined $node_format->att('val')) {
$format_text{UnderlineStyle} = 2;
} else {
$format_text{UnderlineStyle} = 1;
$string_text .= $chunk->text;
}
elsif ($chunk->name eq 's:rPr') {
my %format_text = %default_font_opts;
for my $node_format ($chunk->children) {
if ($node_format->name eq 's:sz') {
$format_text{Height} = $node_format->att('val');
}
}
elsif ($node_format->name eq 's:strike') {
$format_text{Strikeout} = 1;
}
elsif ($node_format->name eq 's:vertAlign') {
if ($node_format->att('val') eq 'superscript') {
$format_text{Super} = 1;
elsif ($node_format->name eq 's:color') {
$format_text{Color} = $self->_color(
$theme_colors,
$node_format
);
}
elsif ($node_format->name eq 's:rFont') {
$format_text{Name} = $node_format->att('val');
}
elsif ($node_format->name eq 's:b') {
$format_text{Bold} = 1;
}
elsif ($node_format->name eq 's:i') {
$format_text{Italic} = 1;
}
elsif ($node_format->name eq 's:u') {
$format_text{Underline} = 1;
if (defined $node_format->att('val')) {
$format_text{UnderlineStyle} = 2;
} else {
$format_text{UnderlineStyle} = 1;
}
}
elsif ($node_format->name eq 's:strike') {
$format_text{Strikeout} = 1;
}
elsif ($node_format->att('val') eq 'subscript') {
$format_text{Super} = 2;
elsif ($node_format->name eq 's:vertAlign') {
if ($node_format->att('val') eq 'superscript') {
$format_text{Super} = 1;
}
elsif ($node_format->att('val') eq 'subscript') {
$format_text{Super} = 2;
}
}
}
push @rich_font_by_cell, [
$string_length,
Spreadsheet::ParseExcel::Font->new(%format_text)
];
}
push @rich_font_by_cell, [
$string_length,
Spreadsheet::ParseExcel::Font->new(%format_text)
];
}
}
}
else {
$string_text = join '', map { $_->text } $si->find_nodes('.//s:t');
else {
# $subnode->name is either 's:rPh' or 's:phoneticPr'
# We ignore phonetic information and do nothing.
}
}

return (
Expand Down
19 changes: 19 additions & 0 deletions t/bug-72.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use utf8;

use Spreadsheet::ParseXLSX;
use Data::Dumper;

my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/bug-72.xlsx');
my $ws = $wb->worksheet(0);

my $b1 = $ws->get_cell(0, 0);
my $b2 = $ws->get_cell(1, 0);

is $b1->value(), "日本語あいうえお";
is $b2->value(), "日本語あいうえお";

done_testing;
Binary file added t/data/bug-72.xlsx
Binary file not shown.