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

fix for absolute path target #34

Merged
merged 1 commit into from Feb 22, 2022
Merged

fix for absolute path target #34

merged 1 commit into from Feb 22, 2022

Conversation

wapa5pow
Copy link
Contributor

@wapa5pow wapa5pow commented Feb 10, 2022

Problem

Some excel library (for example, Styleframe as python library) outputs excel file which contains xl/_rels/workbook.xml.rels file's Target differently as follows.

Cursor_and_StyleframeTest_workbook_xml_rels

With the current spreadsheet_decoder, it generates error.

How to reproduce

To generate excel file which has the problem, execute the following python file.

from styleframe import StyleFrame
from datetime import date


sf = StyleFrame({
    'a': [1],
    'b': [2],
})


ew = StyleFrame.ExcelWriter(r'data.xlsx')
sf.to_excel(ew, 'sheet1')
ew.save()

With the above file, run the following command.

$ pip install styleframe 
$ python convert.py

There will be "data.xlsx" in the same directory.

When read the above file with the current spreadsheet_decoder, it says the following error.
You can use the following file and command to generate the error.

import 'dart:io';

import 'package:spreadsheet_decoder/spreadsheet_decoder.dart';

Future<void> main(List<String> arguments) async {
  final tmp = 'data.xlsx';
  final bytes = File(tmp).readAsBytesSync();
  final decoder = SpreadsheetDecoder.decodeBytes(bytes);
}
$ dart convert_excel.dart 
Unhandled exception:
type 'Null' is not a subtype of type 'List<int>'
#0      XlsxDecoder._parseTable (package:spreadsheet_decoder/src/xlsx.dart:314:49)
#1      XlsxDecoder._parseContent.<anonymous closure> (package:spreadsheet_decoder/src/xlsx.dart:301:7)
#2      Iterable.forEach (dart:core/iterable.dart:279:35)
#3      XlsxDecoder._parseContent (package:spreadsheet_decoder/src/xlsx.dart:300:39)
#4      new XlsxDecoder (package:spreadsheet_decoder/src/xlsx.dart:116:5)
#5      _newSpreadsheetDecoder (package:spreadsheet_decoder/src/spreadsheet.dart:39:14)
#6      new SpreadsheetDecoder.decodeBytes (package:spreadsheet_decoder/src/spreadsheet.dart:76:12)
#7      main (...)
#8      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)```

How to fix

When Target has absolute path, the variable name namePath on the fixed code should not be with xl/$target but target.substring(1).

Related issue

dotnet/Open-XML-SDK#88
tidyverse/readxl#294

@sestegra sestegra merged commit a98df56 into sestegra:master Feb 22, 2022
@sestegra
Copy link
Owner

@wapa5pow Great PR, thanks for contributing to the package.

@wapa5pow wapa5pow deleted the fix-target branch February 23, 2022 09:56
@wapa5pow wapa5pow restored the fix-target branch February 24, 2022 00:51
@wapa5pow wapa5pow deleted the fix-target branch February 24, 2022 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants