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

Style Format is not working #94

Open
mavaras opened this issue Jul 29, 2020 · 6 comments
Open

Style Format is not working #94

mavaras opened this issue Jul 29, 2020 · 6 comments

Comments

@mavaras
Copy link

mavaras commented Jul 29, 2020

Hello, first of all thanks for giving us a great-superfast solution for generate XLS files.

My issue is about that Formats are not working. I've tried several ones with no success, producing no field changes.
I specially want to apply the Percentage one (0.00%), but I've also tried the date one as you show in the README and nothing happens (mm/dd/yy).

I don't know if this is a task in progress or simply a bug.

Thanks in advance.

@kevmo314
Copy link
Collaborator

Do you have some sample code to reproduce the issue? This functionality should be working, we have test cases covering it too.

@mavaras
Copy link
Author

mavaras commented Jul 29, 2020

Here is my Style. The only thing not working is format.

style = Style(
    size=width,
    alignment=Alignment(wrap_text=True),
    format=Format('mm/dd/yy')  # '0.00%' with same behaviour
)

And then applying this to a column:

current_sheet.set_col_style(
    column + 1,
    style,
)

@mavaras
Copy link
Author

mavaras commented Jul 29, 2020

I've also checked your unittests but not found tests about that Format.

@kevmo314
Copy link
Collaborator

Ok, I'll take a look, that's a bit odd.

@kevmo314
Copy link
Collaborator

I took a first pass at this, the style is being populated correctly. For some reason, there's a subtlety in what Excel picks up as a valid reference to the format style. I wasn't able to figure out exactly what was wrong though. That being said, individual cells do format correctly, so

ws[x][y].style.format.format = '0.00%'

should work. It's not quite as nice as formatting the entire column at once, but at least the specific cells can be formatted. I have a hunch that Excel itself may not allow formatting columns and instead actually formats the individual cells too.

If you do figure out what's wrong with PyExcelerate here though, we'd appreciate a pull request. I don't have much bandwidth at the moment so it'll be a while before I can get back to this.

@Slanman3755
Copy link

Having this same issue as well. It looks like ranges and columns also need a special exception in the __get_attr function of Range. This is what's currently in place for rows:

elif self.is_row and isinstance(data, Style.Style):

The error is caused by entering the else statement of this code block and calling len() on the passed Style object.

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

3 participants