Skip to content
New issue

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

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

Already on GitHub? # to your account

set column widths and date format #52

Merged
merged 5 commits into from
Dec 1, 2020
Merged

Conversation

mark-prins
Copy link
Contributor

@mark-prins mark-prins commented Dec 1, 2020

fixes #49
This sets columns widths based on header and row content, using the current font in the template it looks great. There's no guarantee this will always be the case, but it works for now.

Have also formatted dates - which are helpfully returned as float64 values. The parsing is a bit iffy, but once again, it works.

You'll need to update the template ( attached ) as I've merged the date cell so that it looks fine when column 1 is not so wide.

template.xlsx

@mark-prins
Copy link
Contributor Author

and here's how it looks for me...
Expiring Items.xlsx

Copy link
Contributor

@josh-griffin josh-griffin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wicked!

image

Couple minor comments

  • Slightly off when someone is annoying and uses a string with all caps, it seems. Not a big one
  • Maybe commit the template?

func floatToDateString(value interface{}) (string, bool) {
var date string

// dates are returned as float64 values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why.. lol!

func (r *Report) writeCell(sheetName string, cellRef string, value interface{}) {
if date, ok := floatToDateString(value); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having this return false for invoice_printed_date on a [transact], which meant no alignment:
image

I looked a little, but I wasn't able to figure it out. I tried changing the condition which uses milliseconds to using a seconds unix epoch but no dice!

Was hoping to compare the invoice_printed_date field with the one/ones you're using to see if that will uncover the problem!


if len(columns) > 0 {
for columnNumber, column := range columns {
maximumContentLengths[columnNumber] = headerFontCorrectionFactor * float64(len(column.Text))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Headers were a little crammed if the content didn't; surpass the header width: Maybe a little bit of padding? len(column.Text)+3

headerFontCorrectionFactor := 1.35
maximumContentLengths := make(map[int]float64)

if len(columns) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if seems redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, removed

@mark-prins
Copy link
Contributor Author

awesome! thanks @joshxg - both for the review and the inspiration to test against the [transact] table.
found that the dates are coming through as strings for that table, though [item_line] is giving me float64 even though both are date types. End result is that we have a little more date handling 😄

have vertically aligned the numbers, fixed the heading padding and catered for ALL UPPERCASE STRING VALUES TOO.

@mark-prins mark-prins merged commit e57ab01 into master Dec 1, 2020
@mark-prins mark-prins deleted the #49-excel-formatting branch December 1, 2020 23:23
@mark-prins mark-prins mentioned this pull request Dec 1, 2020
@josh-griffin
Copy link
Contributor

PERFECT

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Excel formatting
2 participants