page layout: sheet right-to-left #927

Closed
opened 2017-12-22 17:12:15 +00:00 by mghayour · 4 comments
mghayour commented 2017-12-22 17:12:15 +00:00 (Migrated from github.com)

hi
i need to export right-to-left sheet, that A1 column is in right side of page (not left side)
in microsoft excel we have this option in "Pagelayout" tab > "sheet options" > "Sheet-Right-to-Left"
i searched all readme and codes for "righttoleft" or sth like that, but nothing was founded

are we have this option in sheetjs ?

thank you.

hi i need to export right-to-left sheet, that A1 column is in right side of page (not left side) in microsoft excel we have this option in "Pagelayout" tab > "sheet options" > "Sheet-Right-to-Left" i searched all readme and codes for "righttoleft" or sth like that, but nothing was founded are we have this option in sheetjs ? thank you.
mghayour commented 2017-12-22 18:13:02 +00:00 (Migrated from github.com)

i found it !

i changed source code.
its works correctly.

we should change this line
b3873ea615/bits/67_wsxml.js (L196)

from
return writextag("sheetViews", writextag("sheetView", null, {workbookViewId:"0"}), {});
to
return writextag("sheetViews", writextag("sheetView", null, {workbookViewId:"0", rightToLeft: "1"}), {});

but, as you know, it always use Right-to-Left, you can add an option for it

i found it ! i changed source code. its works correctly. we should change this line https://github.com/SheetJS/js-xlsx/blob/b3873ea61583549a0ce1790b724e2a129ee38eb5/bits/67_wsxml.js#L196 from `return writextag("sheetViews", writextag("sheetView", null, {workbookViewId:"0"}), {});` to `return writextag("sheetViews", writextag("sheetView", null, {workbookViewId:"0", rightToLeft: "1"}), {});` but, as you know, it always use Right-to-Left, you can add an option for it
reviewher commented 2017-12-24 16:35:54 +00:00 (Migrated from github.com)

The sheetViews block should be generated dynamically. If you have patience, we could accept a PR with the following changes:

The spec 18.3.1.88 states that there can be multiple sheet views, so the best place to store the information would be as an array within the Workbook attributes, namely Workbook.Views:

var wb = {
    Workbook: {
        Views: [
            {RTL:true}
        ]
        ...
    }
    ...
    Sheets: {...},
    SheetNames: [ ... ]
}

This would correspond to the following code:

var sview = {workbookViewId:"0"};
if( (((wb||{}).Workbook||{}).Views||[])[0] ) sview["rightToLeft"] = wb.Workbook.Views[0].RTL ? "1" : "0";
return writextag("sheetViews", writextag("sheetView", null, sview), {});

And your code would use:

function set_right_to_left(wb/*:Workbook*/) {
    if(!wb.Workbook) wb.Workbook = {};
    if(!wb.Workbook.Views) wb.Workbook.Views = [];
    if(!wb.Workbook.Views[0]) wb.Workbook.Views[0] = {};
    wb.Workbook.Views[0].RTL = true;
}
The `sheetViews` block should be generated dynamically. If you have patience, we could accept a PR with the following changes: The spec 18.3.1.88 states that there can be multiple sheet views, so the best place to store the information would be as an array within the [`Workbook` attributes](https://docs.sheetjs.com/#workbook-level-attributes), namely `Workbook.Views`: ```js var wb = { Workbook: { Views: [ {RTL:true} ] ... } ... Sheets: {...}, SheetNames: [ ... ] } ``` This would correspond to the following code: ```js var sview = {workbookViewId:"0"}; if( (((wb||{}).Workbook||{}).Views||[])[0] ) sview["rightToLeft"] = wb.Workbook.Views[0].RTL ? "1" : "0"; return writextag("sheetViews", writextag("sheetView", null, sview), {}); ``` And your code would use: ```js function set_right_to_left(wb/*:Workbook*/) { if(!wb.Workbook) wb.Workbook = {}; if(!wb.Workbook.Views) wb.Workbook.Views = []; if(!wb.Workbook.Views[0]) wb.Workbook.Views[0] = {}; wb.Workbook.Views[0].RTL = true; } ```
mghayour commented 2017-12-25 03:18:34 +00:00 (Migrated from github.com)

thank u very much 👍

thank u very much 👍
mahmoudmohamedramadan commented 2022-03-08 17:21:30 +00:00 (Migrated from github.com)

I have written the code that will do this after many tries, the code must be like so

var wb = { Workbook: { Views: [{ RTL: true }] }, Sheets: {}, SheetNames: [] }
var worksheet = XLSX.utils.aoa_to_sheet([insert_your_data_here]);

XLSX.utils.book_append_sheet(wb, worksheet, "Sheet 1");
XLSX.writeFile(wb, "excel_template.xlsx");
I have written the code that will do this after many tries, the code must be like so ```PHP var wb = { Workbook: { Views: [{ RTL: true }] }, Sheets: {}, SheetNames: [] } var worksheet = XLSX.utils.aoa_to_sheet([insert_your_data_here]); XLSX.utils.book_append_sheet(wb, worksheet, "Sheet 1"); XLSX.writeFile(wb, "excel_template.xlsx"); ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#927
No description provided.