C# - Google Sheets API, how to retrieve an image place in cell? - c#

I have a .net core 3.1 console app that I need to use to connect to my Google Sheet and export data to a PDF file.
I can retrieve all the textual data using service.Spreadsheets.Values.Get(spreadsheetId, $"{spreadsheetName}!C2:C8");
The issue I'm facing is that in cells B2:B8 (those are merged cells) I have an image which I've uploaded from my local folder (Image -> Insert -> Image in cell -> Upload) and I can't seem to retrieve that image.
When I call service.Spreadsheets.Values.Get(spreadsheetId, $"{spreadsheetName}!B2:B8"); the Values property returns null
I've tried using =image("IMAGE_URL") in the cell instead of uploading the image but that didn't work as well.
Also, the preferred option would be to use the first approach of uploading the image into the cell so I won't have to find where to store my images.
Is this even possible to accomplish?

That's a very popular feature request
However, as of now it has not been implemented yet - given that images in cells are a rather new feature.
There are however some workarounds - either using Apps Script or a vlookup formula, have a look here.

Related

how can get text from table in pdf file?

I want to get text from table in PDF file?
I cannot get cell in table. I was try to run example of Leadtools but it cannot auto detect cell.
https://www.leadtools.com/help/leadtools/v20/dh/fo/iocrtablezonemanager.html
Can you give me advice? Thanks all
In tables similar to the image you posted, you should be able to find the cells using the IOcrPage.TableZoneManager.AutoDetectCells() method. This method is used in the OcrMultiEngineDemo project that’s shipped with the current version of LEADTOOLS.
Here’s how you can test it:
Run the OCR Multi-Engine Demo.
Select the OmniPage OCR Engine
Open the image or PDF file that contains the table.
Draw a zone around the table.
Choose “Update Zones…” from the OCR->Zones menu.
In the “Update Zones” dialog, click “Detect Cells” as shown in attached image.
If this doesn’t give you the result you’re expecting, send the actual files you’re testing with to support#leadtools.com and explain how you tested exactly.

Paste-Link Excel ranges into C# app

I am writing a C# app where I need to paste/link tables/ranges from existing Excel documents.
Functionality that I am looking for is this:
user can select a range of cells in an open Excel doc and do a Copy
user switches to my C# app and does a past-link ... my app shows the table from Excel.
user can edit the source Excel doc - this does not automatically get reflected in the C# app. But I want to provide a Refresh button that when clicked will update the C# app based on the latest data from the linked Excel sheet.
I have figured out how to do a basic copy/paste. I cannot figure out how to do this paste-link. Please note I do not want to ask user in my C# app for any cell ranges..I simply want to do paste-link of what is already in the clipboard...
Any ideas if this can be done...it is all Microsoft so I would be surprised if it can't be.. but I am a C# novice.
Thanks for all input.
I figured it out. Here are the steps.
User copies a range in Excel sheet. It goes to Clipboard in a number
of formats but CSV and ObjectLink formats are of particular interest.
In C# app, trigger a Paste-Link function (this is any button).
Retrieve data from Clipboard using ObjectLink format. This comes out as text which contains:
Excel version identifier
Path to the excel file
The sheet name and the selected range in R1C1 notation
Save the ObjectLink data in your C# app, we will use it later as part of refresh
Retrieve the data from clipboard using CSV format. Parse it out and present in C# app. I converted it to HTML since this is what I am building
Modify the original source excel file - change something in the cells that were part of the original range - save the file.
Go back to C# app, trigger Refresh functionality (this is any button). IN your code do the following:
Using ObjectLink data saved in step 2, open the Excel sheet in the background using Excel Interop API tools. Select the sheet and range. Copy the range programmatically to clipboard.
invoke the same copy from clipboard as used in the last step of 2. Basically get the updated Excel data in CSV format from clipboard and replace the original representation you built during step 1.
This works like a charm although the COM part of opening an excel doc from C# is a bit slow I have to admit.
I have not found any references to this procedure on the net...works for me like a charm.
Cheers.

How to work with .xls file in C# application

In a C# console application I have a PointF[] array. I need to draw those points in an .xls chart file, but I need guidance how to do this?
Have a look at Open XML SDK 2.0 for Microsoft Office
I've used it before to do something like you're describing.
I started off creating an .xls file in Excel that had the correct chart which read values from a specific range of cells and so on. Then using the SDK I added/changed the values of those cells and saved a new version of the file. So basically I used the file created in Excel as a template that I could change whenever without changing the code (as long as the values are written to the same range of cells).
You could also put the value cells in a separate worksheet so that the user does not see them when opening the file...

How can I export data from Excel to png?

I have a set of Excel spreadsheets with multiple tabs which contains each one table that I need to export as pictures in an automated process (I have dozens of such files to process).
While I could "manually" select the table, copy and paste them as image in another software, I need to industrialize this process to save time.
What would be the best approach using .Net or any builtin Excel feature?
Thanks
Check this question.
Programmatically (C#) convert Excel to an image
It looks like they're doing what you need?
Think I would use a small C# apop to do it - that assumes that you have a one off task and don't want to mess about with Excel templates or global excel macros and opening each spreadsheets etc.
I would do it like this:
dump all my excel docs in a single folder.
open up each doc in the folder in C# app
iterate each tab
If data capture data for all used ranges (from A1 to the whatever the bottom right cell is) - for any embedded charts pull them off as well
If chart pull it off
dump each to the folder as an image prefixed with the excel doc name and some iterative suffix like _chat01 _data01
How to rwead it ina and convert to image? See here => http://csharp.net-informations.com/excel/csharp-excel-chart-picturebox.htm
Copy all desired cells
Open MS-Paint
Paste
Save as PNG.

SSRS Excel output sorting image problem

When exporting my simple data report to Excel (Using ReportViewer in localmode) I can sort the table data fine but I have images in all of the rows and they do not sort with the data.
My basic setup is a C# class that provides a List<> of a data type with a few columns and a byte[] image in it as an object data source.
I just dragged an image item into the table and set it up as from Database and MIME type jpeg.
Anyone know how I can enable sorting of my Excel output?
Thanks,
Phil
Edit:
I'm trying to sort via selecting the cells and then going Sort. Not using the filter button.
I'm Using Excel 2007.
Unfortunatly the images are mini graphs that represent quickly what each row means and are really vital when looking through the data.
I do not think this is possible, as images do not attach to cells but instead positioned fixed distance from the left and top of the spreadsheet. This is Excel behaviour, not related to SSRS itself producing the spreadsheet. It's certainly not possible in 2003 and below, but I've not tried Excel 2007.
Possibly you could get SSRS to export hyperlinks to the images instead of the images themselves, in which case you could sort the data without orphaning the image references.
odd. i just exported a report of mine that has images and they sort fine. are you using the filter button or are you just selecting the cells and click the sort button?

Categories