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

Can't print cell contents #462

Closed
AngangGuo opened this issue Aug 7, 2019 · 8 comments
Closed

Can't print cell contents #462

AngangGuo opened this issue Aug 7, 2019 · 8 comments

Comments

@AngangGuo
Copy link

The following program can't print the contents of the last two cells:

go.mod

module report

go 1.13

require github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2-0.20190731155349-9279c86d85ab
package main

import (
	"fmt"
	"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
	var fileName = "User Metrics.xlsx"
	var sheetName = "User Metrics"

	f, _ := excelize.OpenFile(fileName)
	contents, _ := f.GetRows(sheetName)

	for i,j:=range contents[2]{
		fmt.Println(i,j)
	}
}

Output:

0 Employee Name
1 Clean & Pack
2 Data Erasure
3 FG (Client)
4
5 FG(RL-LIQ)
6 Rebox
7 Repair Without Parts
8 Sort
9 Test
10
11
// missing the following contents:
// 10 Sort Weight (Kgs)
// 11 Test Weight (Kgs)

User Metrics.zip

@mlh758
Copy link
Contributor

mlh758 commented Aug 7, 2019

Here is the XML for those cells:

<c s="3" t="inlineStr" r="K3">
  <is>
    <r>
      <rPr>
        <b></b>
        <i val="0"></i>
        <strike val="0"></strike>
        <u val="none"></u>
        <sz val="9"></sz>
        <color rgb="FFFFFFFF"></color>
        <rFont val="Tahoma"></rFont>
      </rPr>
      <t xml:space="preserve">Sort Weight (</t>
    </r>
    <r>
      <rPr>
        <b></b>
        <i val="0"></i>
        <strike val="0"></strike>
        <u val="none"></u>
        <sz val="9"></sz>
        <color rgb="FFFFFFFF"></color>
        <rFont val="Tahoma"></rFont>
      </rPr>
      <t xml:space="preserve">Kgs</t>
    </r>
    <r>
      <rPr>
        <b></b>
        <i val="0"></i>
        <strike val="0"></strike>
        <u val="none"></u>
        <sz val="9"></sz>
        <color rgb="FFFFFFFF"></color>
        <rFont val="Tahoma"></rFont>
      </rPr>
      <t xml:space="preserve">)</t>
    </r>
  </is>
</c>

Looks like you can have nested rows within an inline string (<is>) tag which we definitely aren't accounting for:

type xlsxIS struct {
	T string `xml:"t"`
}

We'll need to expand that struct and probably add a method on it to extract the string. For the purpose of reading files I propose that getValueFrom should call a method on xlsx.IS which returns a string instead of directly accessing the T field. Rows should be joined with a newline character.

@mlh758
Copy link
Contributor

mlh758 commented Aug 7, 2019

What did you use to create this file? The repeated inline formatting instructions seems strange to me.

@AngangGuo
Copy link
Author

The file is generated from our company software.

@mlh758
Copy link
Contributor

mlh758 commented Aug 7, 2019

Ah some some internal program your company made/uses is making the file?

In any case, this will require a PR, we're just not handling this part of the spec yet.

@mlh758
Copy link
Contributor

mlh758 commented Aug 7, 2019

Try out the code in this PR. It worked for me with your sample file.

@AngangGuo
Copy link
Author

Can you please give me some instruction on how to use your PR code?
thanks.

@mlh758
Copy link
Contributor

mlh758 commented Aug 8, 2019

Assuming you are using go modules, you can clone my fork of the repo with that branch and then add a replace directive like this:

replace github.com/360EntSecGroup-Skylar/excelize/v2 => /path/to/the/fork

Then go build like normal. This would just be to verify the fix works for you. Don't leave that replace directive in forever since I'm going to delete the branch once this PR merges.

@AngangGuo
Copy link
Author

Tested. It works well.
Thanks.

@xuri xuri closed this as completed in acd7642 Aug 10, 2019
xuri added a commit that referenced this issue Aug 10, 2019
Fixed #462 Handle multi row inline strings
nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
The inline string struct is actually the same
as the shared strings struct, reuse it.

Note that Go version 1.10 is required.

Fixes qax-os#462
nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
Fixed qax-os#462 Handle multi row inline strings
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

No branches or pull requests

2 participants