SSRS Excel output sorting image problem - c#

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?

Related

Dynamic Excel columns and rows to SQL

I have an Excel template which has dynamic rows and columns (it means the Excel template will be downloaded based on the parameters I select in my UI). Now there will be some data in the Excel sheet against those dynamic rows and columns coming from the database. I want to modify that Excel and import it so that only the updated(modified) cell values are updated in database. I thought a lot and I think this can be done with macros (by changing the color of cells with updated values and picking them up from C#). I would welcome any other thoughts/approaches for this.
An approach I have used is to create a webdav/REST service which can then be mounted as a drive in Windows.
The exposed file on the webdav service was simply a CSV, which users could edit in Excel, but the GET request was serviced by reading the database.
After making the changes, the user saved in Excel, which caused a PUT on the webdav service. The PUT request wrote the new values to the database.

EPPlus / How to get data from pivot table? Or how to manipulate data easily?

I am wasting very much time on manipulating data in reports. Using pivot table is a good idea but how? I tried some free PivotTable classes but they were lacking subtotals.
Then, another approach. For excel output of reports I am using EPPlus. It also supports pivottable. The problem is some of our customers do not have office(OpenOffice, MicrosoftOffice etc.), so just creating and saving an xlsx file does not work. The only thing I can try with EPPlus is creating an ExcelPackage, filling a worksheet with data, and then creating a PivotTable with data.
I have several questions;
1) From that PivotTable object can I access the output of PivotTable fields and values. (Up to now I could not).
2) Related to the above question... Does an xlsx file contains data about the PivotTables or just the rules of creating PivotTable(Like name of table, sourceRange, rowFields, columnFields, dataFields, aggregate options etc). I have made a small test about this. Steps as following:
Opened a new excel file.
Inserted some raw data.
Created pivot table with the data.
Changed some values of data. (without refreshing pivot table)
Saved and closed the file.
Opened the file back.
In fact my guess was "pivot table would update according to new data", but I was wrong. It did not update. This may be a proof for "xlsx file contains not only rules for a pivot table but also all the values of it". If this is so I have a hope to access that data without saving the file (and I do not need any office programs).
3) Any other approach appreciated.
Thanks in advance
I am by no means an expert on EPPlus but have been working with it for the past few months and can hopefully shed some light on your questions.
If you create a brand new xlsx in EEP, add data to a worksheet, create a pivot table pointed at the data/worksheet, and save it - then the PivotTable does NOT contain any data. It merely contains the definition of the how the PT should slice the data when the file is opened in excel (as you mentioned in one of your questions).
When you actually open the file in excel and SAVE IT what excel does is copies all of the data that the PT relies on and puts it in the pivot table cache. This is why you can then delete the original cells that contained the data, save the file, and then reopen it in excel (might have to dismiss some errors), and still see the PT with data. You can even double click on one of the data cells in the PT and excel will regenerate some or all (depending on which cell you clicked) of the associated data into a new sheet.
Yes, your guess was in fact wrong because of this pivot table cache. You have to tell excel to update the data source in the proper Ribbon (assuming the data is still there) to see the new data show up.
So, to access the data you can figure out where it sits by going into the PivotTable.WorkSheet object and pulling the data out from that. You can see how I did it in the extension method i created here:
Create Pivot Table Filters With EPPLUS
Another option would be to extract the actual worksheet.xml file from the xlsx. An xlsx file (and any other MS Office .???x files) are just ZIP files renamed. So you can use the standard .NET methods to get the xml files out of the zip and use something like LinqToXml to extract the data. So something like this:
var zip = new ExcelPackage(file).Package;
var recordspart = zip.GetPart(new Uri("/xl/worksheets/sheet1.xml", UriKind.Relative));
var recordsxml = XDocument.Load(recordspart.GetStream());
It wont be pretty doing all the XML manipulation but if a final format of XLSX will not work it may be your best option.

Warehouse management using Excel and C#

I need basic idea on warehouse management using Excel and C#.
Actually, the warehouse file consist of 30 columns and 40,000 above record.
I need to select only select columns (suppose-12) from the uploaded Excel file (.XLSX)
I need to display 40,000 rows of data (all) with customized columns
Provide user auto search text-boxes (suppose for 5 columns-like truck no, order no, orderdate, wh-name) and display the search result at grid view
Edit and update the data searched by auto search (any row or implement update for all rows)
finally save the data into a new Excel or PDF file
Please help to implement these, using C# and Excel.
I tried but it takes 7-10 mins to save data from datagrid to new Excel file. I have problem with dynamic auto search columns
As a Suggestion: use http://epplus.codeplex.com/ to read the incoming file. Then put all the incoming material in some DataTables.
These DataTables could be used to implement the other functions way easier, since they are build to support that kind of actions.
Save any modified data to these Datatables.
Export them to a new xlsx file, that you can hand back. Agian, you can use epplus

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.

How to update different embebbed charts on Powerpoint with openxml?

I want to update various charts on openxml Powerpoint file using openxml sdk 2.
I have managed to update the data on the excel sheet that feeds the chart and the chart itself. but that's not very efficient because i end up doing the same thing twice (updating the embedded excel and the chart object with the same data) and also because the chart object's xml structure is different for different chart types, so more should-be-unnecessary code and probably more bugs.
I wonder if there is a way to tell the Chart to update itself with the new data on the excel.
I also tried to use the AutoUpdate property of the chart but without any results. This is a follow up question. The first one was this one: How to make a powerpoint chart reflect changes to its data source?
To my knowledge, what you are looking for (frustrating as it is) is not possible.
I've been in the exact same position with word documents, and ended up doing a method for each type of chart I knew my code would encounter.
I don't believe there is a trigger for you to force an update upon opening word.
But I would love to be proved wrong.
Editing to clarify.
Yes, you can update the charts by only updating the data-caches in xml and not the embedded parts, however, you then end up with a word document in which, if you double click a chart to vidw the data-source, you'll get another data-source than the one shown in the document. Further more, when you close the data-source (the embedded excel) the chart will update to the values from the embedding.
In short. Unless you intend to PDF your document or something like that, it is advicable to update both the embeddings and the xml-charts.

Categories