Dynamic Excel columns and rows to SQL - c#

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.

Related

Address Google Sheet address which would not be affected by viewer sorting (Using C# API)

I am using the Google sheet API (C#) to process data stored in a sheet.
My application processing is as follow:
Input to the application is a list of data,
Grab one item from the list
Find the associated row in the sheet
based on the sheet data, decide to process some external data (This may take several minutes).
tag the row that data is processed.
In my solution, I read the spreadsheet to a list and then when I want to tag it, I use row number to find the cell to tag.
But if a viewer changes the order of data (for example by sorting or filtering) then the above method doesn't work.
Any better way to work with sheet that viewer sort or filtering doesn't affect it?
You can make use of Google Sheets Developer Metadata
As specified in the documentation:
Developer metadata may be used to associate arbitrary data with
various parts of a spreadsheet and will remain associated at those
locations as they move around and the spreadsheet is edited. For
example, if developer metadata is associated with row 5 and another
row is then subsequently inserted above row 5, that original metadata
will still be associated with the row it was first associated with
(what is now row 6).

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.

Retrieve dynamic values from Excel

Objective
To retrieve values from Excel sheet that is changing each second.
Efforts so far
Created shared excel file so that it can be retrieved by more than two processes simultaneously.
Tried to read excel file that is receiving updates from RTD Server. The file is changing cells values each second. I read it by using Microsoft.Office.Interop.Excel
Simultaneously accessing data from excel file into GridView using System.Data.OleDb.
Looking for
How to read those dynamic values from excel sheet? Because until those values are not saved, I can't read them from code they way I am doing now.
I believe that there should be way for accessing those changing values in cells. But I am not gettig any hint.

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

Dynamically creating populating templated MS Office Excel files using schema, and data, stored in Database

I have an Excel file we consider a template file. Currently, user downloads the file and then manually inputs data into the file column/row by row. What I would want to do however is save this template to a database, and then, on request, dynamically create an excel worksheet using this saved template, and then proceed to populate the columns and rows of the templated excel file with data from other database tables. the following are some of the questions I currently have --
How do I extract the schema for the template from the excel template file?
How do I create an excel file using the extracted template information?
How do I ensure that when I start to populate the created file with data, I start on the right row and column?
How do I solve these please? Any good examples of how this could done, out there?
Also, where is the Microsoft Office SDK download site? I have been searching all day.

Categories