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

Spreadsheet toJSON() does not contain Workbook images info #6411

Open
veselints opened this issue May 10, 2021 · 6 comments
Open

Spreadsheet toJSON() does not contain Workbook images info #6411

veselints opened this issue May 10, 2021 · 6 comments

Comments

@veselints
Copy link
Contributor

veselints commented May 10, 2021

Bug report

Spreadsheet toJSON() does not contain Workbook images info. As a consequence, the e.workbook parameter in the excelExport event does not contain images info, even if its sheets have drawings.

Reproduction of the problem

Call spreadsheet.toJSON() on a Spreadsheet that has some images inserted. The JSON definition will not have images even if it has drawings for its sheet(s).

Expected/desired behavior

Images info should be present in the exported JSON

Environment

  • Kendo UI version: 2024.1.130
  • Browser: [all]

Bug report in Common Engine

@kendo-bot kendo-bot added the FP: Unplanned Sync status with associated Feedback Item label May 10, 2021
@veselints
Copy link
Contributor Author

veselints commented May 12, 2021

The images data could be retrieved from the Spreadsheet itself following this logic:

function loadBinary(url, callback) {
  var xhr = new XMLHttpRequest();

  xhr.onload = function () {
    callback(xhr.response, xhr.getResponseHeader("Content-Type"));
  };

  xhr.onerror = function () {
    callback(null);
  };

  xhr.open("GET", url);
  xhr.responseType = "arraybuffer";
  xhr.send();
}

function next() {
  if (--countOfImages <= 0) {
    workbook.images = images;
  }
}

var images = {};
var spreadsheet = $("#spreadsheet").getKendoSpreadsheet();
var wbImages = spreadsheet._workbook._images;
var keys = Object.keys(wbImages);
var countOfImages = keys.length;
var workbook = spreadsheet.toJSON();

if (countOfImages) {
  keys.forEach(function (id) {
    var url = wbImages[id].url;

    loadBinary(url, function (data, contentType) {
      images[id] = { type: contentType, data: data };
      next();
    });
  });
}

Or better, retrieve images directly from Blob objects:

function next() {
  if (--countOfImages <= 0) {
    workbook.images = images;
  }
}

var images = {};
var spreadsheet = $("#spreadsheet").getKendoSpreadsheet();
var wbImages = spreadsheet._workbook._images;
var keys = Object.keys(wbImages);
var countOfImages = keys.length;
var workbook = spreadsheet.toJSON();

if (countOfImages) {
  keys.forEach(function (id) {
    var blob = wbImages[id].blob;
    var contentType = blob.type;

    blob.arrayBuffer().then((buffer) => {
        images[id] = { type: contentType, data: buffer };
        next();
    });
  });
}

@nelito987
Copy link
Contributor

Reported in ticket ID: 1520163

@veselints
Copy link
Contributor Author

Related to: #6529

@nelito987
Copy link
Contributor

Reported in ticket ID: 1551883

@Iankodj
Copy link
Contributor

Iankodj commented Aug 29, 2022

Reported in ticket ID: 15981

@nelito987
Copy link
Contributor

Reported in ticket ID: 1608333

@pepinho24 pepinho24 added dependencies Pull requests that update a dependency file Dependency and removed dependencies Pull requests that update a dependency file labels Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants