Skip to content

[FIX] figures: fix xlsx export #6251

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

Open
wants to merge 1 commit into
base: saas-18.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/xlsx/conversion/figure_conversion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FIGURE_BORDER_WIDTH } from "../../constants";
import {
getFullReference,
isDefined,
Expand Down Expand Up @@ -140,8 +141,8 @@ function convertExcelRangeToSheetXC(range: string, dataSetsHaveTitle: boolean):

function convertAnchor(XLSXanchor: XLSXFigureAnchor): AnchorOffset {
const offset = {
x: convertEMUToDotValue(XLSXanchor.colOffset),
y: convertEMUToDotValue(XLSXanchor.rowOffset),
x: convertEMUToDotValue(XLSXanchor.colOffset) - FIGURE_BORDER_WIDTH,
y: convertEMUToDotValue(XLSXanchor.rowOffset) - FIGURE_BORDER_WIDTH,
};
return { col: XLSXanchor.col, row: XLSXanchor.row, offset };
}
Expand Down
2 changes: 1 addition & 1 deletion src/xlsx/functions/drawings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function figureCoordinates(
for (const [headerIndex, header] of headers.slice(anchor).entries()) {
if (currentPosition <= offset && offset < currentPosition + header.size!) {
return {
index: headerIndex,
index: anchor + headerIndex,
offset: convertDotValueToEMU(offset - currentPosition + FIGURE_BORDER_WIDTH),
};
} else if (headerIndex < headers.length - 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/xlsx/xlsx_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getXLSXFilesOfType } from "./helpers/xlsx_helper";
import { XLSXImportWarningManager } from "./helpers/xlsx_parser_error_manager";
import { escapeTagNamespaces, parseXML } from "./helpers/xml_helpers";

const EXCEL_IMPORT_VERSION = "18.3";
const EXCEL_IMPORT_VERSION = "18.3.1";

export class XlsxReader {
warningManager: XLSXImportWarningManager;
Expand Down
21 changes: 21 additions & 0 deletions tests/xlsx/xlsx_import_export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,25 @@ describe("Export data to xlsx then import it", () => {
expect(newFigure.width).toBe(300);
expect(newFigure.height).toBe(400);
});

test.each([
{ offset: { x: 0, y: 0 }, col: 5, row: 5 },
{ offset: { x: 10, y: 10 }, col: 10, row: 10 },
{ offset: { x: 0, y: 10 }, col: 5, row: 0 },
{ offset: { x: 10, y: 0 }, col: 0, row: 5 },
])("Figure Position", (position) => {
createImage(model, {
figureId: "1",
size: {
width: 300,
height: 400,
},
...position,
});

const figure = model.getters.getFigures(sheetId)[0];
const importedModel = exportToXlsxThenImport(model);
const newFigure = importedModel.getters.getFigures(sheetId)[0];
expect(newFigure).toMatchObject(figure);
});
});