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

!rows array, page view & margins, image support #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Siguza
Copy link

@Siguza Siguza commented Feb 5, 2016

Credit: !rows handling: paulish

View usage:

XLSX.write(wb,
{
    // ...
    view: 'pageLayout',
    zoomScale: 140,
    zoomScaleNormal: 100,
    zoomScalePageLayoutView: 140,
});

Margin usage:

XLSX.write(
{
    SheetNames: ['Example'],
    Sheets:
    {
        Example:
        {
            // ...
            '!pageMargins':
            {
                left: 0,
                right: 0,
                top: 0,
                bottom: 0,
                header: 0,
                footer: 0,
            },
        },
    },
}, opts);

Images usage:

XLSX.write(
{
    SheetNames: ['Example'],
    Sheets:
    {
        Example:
        {
            // ...
            '!drawing': 0, // Index in wb.Drawings
        },
    },
    Drawings:
    [ // Array of drawings
        [ // Drawing = array of images
            {
                image: 0, // Index in wb.Images
                from:
                {
                    col: 0,
                    row: 0,
                    colOff: 1335173,
                    rowOff: 107424,
                },
                to:
                {
                    col: 0,
                    row: 0,
                    colOff: 1729508,
                    rowOff: 243441,
                },
            },
            // ...
        ],
    ],
    Images:
    [
        {
            data: '...', // <base64 data without "data:..." header>
            type: 'png', // the only supported type for now
        },
        // ...
    ],
}, opts);

@seriousben
Copy link

seriousben commented Jun 9, 2016

@protobi if the images part of this PR were extracted and made into another PR. Would you accept it?

@seriousben
Copy link

@Siguza how functional were your changes before the conflict?

@Siguza
Copy link
Author

Siguza commented Jun 10, 2016

Fully functional, I'd say. Limited, but functional.

For image support, using the dist from my fork you should be able to literally copy the last code block from my PR, replace the ... in data with some base64 encoded PNG and get an XLSX with an embedded image.

Everything else is fairly simple and only required a handful of XML tags or attributes to be added or set.

@seriousben
Copy link

Thanks a lot!

@eric-borland
Copy link

The image handling would be a great feature (It's sad, but our client uses images on excel files). Do you guys have any plan on fixing + merging this branch soon? Or to separate the image development in another PR?

Thank you all very much for this awesome module!

@adamtaylor13
Copy link

Is this project dead? I've got a pretty serious issue and it doesn't seem anyone is even replying to issues anymore. (#39)

@Siguza
Copy link
Author

Siguza commented Jul 22, 2016

Well I'm still around, but I only forked the repo and hacked image support together.
I suppose I could try and write up a fix for that issue of yours though, if you can provide me with an xlsx both pre- and post-repair.

@adamtaylor13
Copy link

Well I wouldn't actually mind trying to write the fix myself if I could figure out what exactly is causing the issues. The only reason I'm hesitant to provide the before/after .xlsx is because it contains government records.

However, if you can get me a general idea of where the issue may be occuring, I'd love to try to fix it myself. I think I provided as much info as I could get under my issue (linked in the prior comment)

@Siguza
Copy link
Author

Siguza commented Jul 22, 2016

The most likely source of a bug in worksheets/sheetX.xml would seem bits/67_wsxml.js.
Without knowing the nature of the bug though (missing tag/attribute that is expected, XML syntax error, ...), I don't think I can tell more.
But I suggest you create a before/after pair, unzip both of them, run both xl/worksheets/sheet1.xml through an XML beautifier and compare them. That would reveal the exact place and nature of the bug, which should in turn allow you to track it to the code that generates the XML portion in question.

@pietersv
Copy link
Collaborator

I'd love to support the project more. The challenge for me is that the base project is silent. There are tens of thousands of unit tests for the server and browser, and these catch a surprising number of issues with seemingly simple edits. So I'm hesitant to accept PRs without running the tests.

However, the base project combined XLSX with XLS, XLSB and XLSM into one project and some of these no longer work in Node 4+. Ideally, the base project would work with Node 4+, I pull those changes in and roll along. I've been hoping that would happen by now. Even better would be for the base project to handle styles, and we all support that.

I think the root issue here is the economics of open source which requires one small group with the skill and intensity to manage the core. I can make the business case to support the styles extension but not the XLS/XLSB or node migration part.

@adamtaylor13
Copy link

Yeah that makes sense to me. Unfortunately I don't feel like I have the expertise to get my hands really dirty with these types of migrations/updates. I really wish the base project wasn't dead. This seems like a very useful project that just kind of died.

@SheetJSDev
Copy link

@Siguza we were looking at an issue SheetJS#509 which appears to have plucked changes from your PR. Nice work!

We already pulled in the core of the changes from @paulish PR but have yet to finalize the row parameters.

With regards to the page margins, is there any particular reason for the defaults you chose? The UI for Excel 2007 and Excel 2016 both quote rounded decimals:

excel2007pagemargins

And for completeness sake, here are a few sample files (and they show the same numbers as the UI):

page_margins_2007.xlsx

page_margins_2016.xlsx

Since the file has no conception of "wide/narrow/normal", only the raw numbers, it makes sense to merely document the sizes in the README but default to the normal values.

@Siguza
Copy link
Author

Siguza commented Apr 12, 2017

@SheetJSDev:
I got those values directly from some XML files I generated, though I'm not sure where they originally come from. They do correspond to rounded centimetre values though, so I probably just changed my defaults at some point (I didn't even realise the values in the XML were inches until today ^^).
Happy to see my work is useful after all. :)

@SheetJSDev
Copy link

@Siguza in Excel, if you go to page layout and hit the margins button, you'll see a dropdown. Can you read off what is written there? The margins according to your files are:

margin size
left/right 18 mm
top/bottom 19 mm
header/footer 8 mm

@Siguza
Copy link
Author

Siguza commented Apr 12, 2017

The values don't match my current ones.

margin size
left/right 1.778 cm
top/bottom 1.905 cm
header/footer 0.762 cm

This is a fresh install, so my old values were most likely custom.

@SheetJSDev
Copy link

@Siguza we just pushed a change in the main repo to add page margin parsing for the main formats as well as page margin writing for XLSB: SheetJS@1587688#diff-d3b36db34e6b01d5a4720fd524e20279. If you can fork the main repo and add in the XLSX write stuff, we'd accept a PR. Also check your email :)

SheetJSDev pushed a commit to SheetJS/sheetjs that referenced this pull request Apr 17, 2017
changes distilled from Siguza/js-xlsx
see protobi#19 for discussion
@gdoteof
Copy link

gdoteof commented Aug 25, 2017

Wanted to add I worked a bit on images -- I needed to be able to add multiple and set some properties (offsets and sizes).

#84

honestdeveloper1985 added a commit to honestdeveloper1985/js-xlsx that referenced this pull request Nov 18, 2018
changes distilled from Siguza/js-xlsx
see protobi/js-xlsx#19 for discussion
RimaCiklum pushed a commit to Folcon/js-xlsx that referenced this pull request Aug 20, 2020
changes distilled from Siguza/js-xlsx
see protobi#19 for discussion
KingTiger001 added a commit to KingTiger001/sheet-project that referenced this pull request Dec 18, 2022
changes distilled from Siguza/js-xlsx
see protobi/js-xlsx#19 for discussion
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

7 participants