question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to locate a picture?

See original GitHub issue

How do I tell which row and column the picture belongs to?

const Excel = require('exceljs')
var workbook = new Excel.Workbook();
workbook.xlsx.readFile('test.xlsx')
    .then(function () {
        // fs.writeFileSync('1.png', workbook.getImage(0).buffer)
        var worksheet = workbook.getWorksheet('sheet1');
        console.log(worksheet.getCell('AY2').style.border)
        console.log(worksheet.getImages()[1])
        console.log(worksheet.getImages()[0])
    });
{ left: { style: 'thin', color: { indexed: 8 } },
  right: { style: 'thin', color: { indexed: 8 } },
  top: { style: 'thin', color: { indexed: 8 } },
  bottom: { style: 'thin', color: { indexed: 8 } } }
{ type: 'image',
  imageId: 0,
  range:
   { tl: { col: 49.5854015625, row: 2.8599277777777776 },
     br: { col: 52.926940625, row: 10.136783333333334 } } }
{ type: 'image',
  imageId: 1,
  range:
   { tl: { col: 50.283765625, row: 1.4515555555555555 },
     br: { col: 53.239728125, row: 6.94735 } } }

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
arimuscommented, Sep 17, 2020

I was trying to match things up, but in my case I had images bound to the cell. This means I didn’t need to fuzzy find the row/col because they were exact. But in any case I still had the issue of correlating images with the proper cells. Here is what appears to work. It may not be correct for all cases, but functionally appears to be working on first pass and I wanted to share:

  const ExcelJS = require('exceljs');
  const workbook = new ExcelJS.Workbook();
  const data = await workbook.xlsx.readFile('./test.xlsx');

  const worksheet = workbook.worksheets[0];
  for (const image of worksheet.getImages()) {
    console.log('processing image row', image.range.tl.nativeRow, 'col', image.range.tl.nativeCol, 'imageId', image.imageId);
    // fetch the media item with the data (it seems the imageId matches up with m.index?)
    const img = workbook.model.media.find(m => m.index === image.imageId);
    fs.writeFileSync(`${image.range.tl.nativeRow}.${image.range.tl.nativeCol}.${img.name}.${img.extension}`, img.buffer);
  }

This will write all the files out in row / col order.

0reactions
lastheadcommented, Jul 18, 2022

I was trying to match things up, but in my case I had images bound to the cell. This means I didn’t need to fuzzy find the row/col because they were exact. But in any case I still had the issue of correlating images with the proper cells. Here is what appears to work. It may not be correct for all cases, but functionally appears to be working on first pass and I wanted to share:

  const ExcelJS = require('exceljs');
  const workbook = new ExcelJS.Workbook();
  const data = await workbook.xlsx.readFile('./test.xlsx');

  const worksheet = workbook.worksheets[0];
  for (const image of worksheet.getImages()) {
    console.log('processing image row', image.range.tl.nativeRow, 'col', image.range.tl.nativeCol, 'imageId', image.imageId);
    // fetch the media item with the data (it seems the imageId matches up with m.index?)
    const img = workbook.model.media.find(m => m.index === image.imageId);
    fs.writeFileSync(`${image.range.tl.nativeRow}.${image.range.tl.nativeCol}.${img.name}.${img.extension}`, img.buffer);
  }

This will write all the files out in row / col order.

Thank’s a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 Ways To Find Where a Picture Was Taken - Online Tech Tips
6 Ways To Find Where a Picture Was Taken · EXIF Data Is Always The First Stop · Search GPS Coordinates On Google...
Read more >
Where was that photo taken? How to locate (almost) any place ...
To find an image's exif data, right-click the photo and select either “properties” or “information”. If the GPS coordinates appear, ...
Read more >
How To Find Out Where a Picture Was Taken - Alphr
1. Go to the image. 2. Right-click and choose “Copy image address.” 3. Visit Google Images and paste the image address in the...
Read more >
How to Find the Location Where a Photo Was Taken - Techbout
Access Location Information Attached to a Photo · 1. First, download the Photo to your Windows Computer or Mac · 2. Next, right...
Read more >
How to Find Out Where A Photo Was Taken & Track GPS ...
Detect Location from Photo via Google Maps ... After getting GPS information on the picture, a user can find the location where the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found