Getting real time values from an excel feed - c#

Hello
My application from the stockbroker has this button called "Start excelfeed" which opens an excel file and then updates the incoming prices in realtime. I want these prices extracted into my application (Java), but after several tries with jxl and poi ive found out it only extracts the values which occurred last time i saved the excel files. Are there any possible ways to extract these prices in real time? I'm not sure which method theyre using to feed the excel file, except their app is written in C#.

You can have a look at the VBA code behind the "Start excelfeed" button by hitting Alt+F11 ... Then you can check how the excel macro taps into the data source und try to adapt that in Java
[EDIT]
#Zico Sorry then I got you wrong. In that case I'd try to automate it via the Java Robot Class like user489041 suggested or you could fire up wireshark and try to snoop around the network traffic

They are using the DDE technique and you should use excel automation to pull data from excel into your app.

In the old days, we used DDE links. Chances are your stockbroker addin uses precisely that.
Chances of using DDE from java are pretty slim (close to zero) because it is windows specific. However, possibly there are other methods involved (like COM components or TCP/IP connection). I'd suggest you get the values from teh stockbroker source like the Excelfeed, instead of going through Excel.
Of course, the problem with that is that you won't get help from the vendor of the Excel addin. If things are like they were 8 years ago, they are making tons on your buying the Excel addin and don't really want to help you program against that :)

Worst case, you could use the Java Robot class to create the Excel spreadsheet, save the Excel spreadsheet as a CSV file, then read the CSV file from your Java program.

You can do this with solutions like Obba. Obba allows to access a Java virtual machine running the "Obba Server" directly from Excel.
For your problem, you have to "create" your application from the spreadsheet (load the jar, create an object representing you app - e.g. launching it in a separate thread). Then you can feed the app from Excel... - In this case, Excel is to some extend the "control program" of your app. However, if you start the Obba Server process manually, the process will keep on running if you close and re-open Excel.

Related

How to persist data in Excel (VSTO) shared among few users?

I have to load huge amount of data, pre-process it, share it among few users and finally gather updates back from users.
This is what I did in my previous project -
Created an excel add-in using C++. Loaded the data in memory using the add-in code and processed it. For each type of data I have sent the processed data to a sheet and saved a new excel file. That way, if I have three types of data, I have created three new excel workbooks. My users then opened those new workbooks, made their changes and dropped a text file that contains their changes (through a button). The main excel keeps polling for those updates (text files) and loads them as soon as they are found. That's the way I get the updates back from my users.
I am not a fan of what I did in my previous project, it produces too many temporary files (of course I can delete those). In my current project I want to use C# VSTO Workbook so I can have more control over excel. I was hoping once I load the data, I will ask my users to open the same excel in Read-Only mode and they will make changes. While testing this, I realized user's excel (opened in read-only) mode does not see the loaded data. And their changes do not update the data held in memory. This probably means I have no idea what I am doing.
Do you guys have any idea how to achieve this? I will really appreciate any help/hint.
Excel supports so-called "co-authoring" mode, when many people can edit the same document at the same time. But there is might be a catch: afaik, you need a Share Point/Office Online server/OneDrive Business to support this scenario (you need a non-free office document server product).
Using VSTO, you can do just the same you have done with C++ add-in, but in C# (means, the set of capabilities is 1:1 - it basically just wraps C++ COM Excel API for .NET)
But for online version of Excel, there may be yet another alternative - javascript addins (now that's called "Office Addins", afaik). But I doubt you'd want to process your "huge amounts of data" with javascript.
So I would say, there is a good rule: Don't fix something that isn't broken :)
If the problem is the number of temporary files, these files is not the only option to transfer data between applications. You know, you can connect two applications directly (so that they can exchange data with messages/updates). Use network, Luke :)
Of course if your 3 users live on 3 deserted islands, totally disconnected from anything, exchanging with text files on USB stick may still be the only viable option...
I think the "web" solution could be: store your file in some "co-authoring"-capable service (sharepoint, google shees, onedrive, officeonline, whatever). Make some web job to update that file in that storage automatically. Just like a "fourth" user would do.

Writing on open Excel application using NPOI

folks,
Environment
Windows 8.1
Visual Studio 2013
C#
Issue
How do I write values and make charts on visible Excel sheets using NPOI (https://npoi.codeplex.com/).
Why do I want that?
I'm developing an application to measure temperature in an apparatus. To put together experimental data in one place, I'd like to record data on an Excel sheet and make a chart on the sheet. In addition, I'd like to keep the Excel sheet visible and check the chart updated in real time.
You could also make graphs on Windows Form apps with MeasurementStudio by NationalInstruments for example but considering the flexibility of Excel charts (size and xy range changeable, easy-to-use user interface, etc...), I'd like to stick to Excel.
You can easily do this with Microsoft.Office.Interop.Excel by
ExcelApp.visible = true;. However, this module requires users to release every COM object generated. Otherwise, the objects remain and eat up memory. This is the reason I prefer to use NPOI.
How can I achieve this? Any answers would be appreciated.
You cannot do this with NPOI. NPOI reads and writes data from serialized Excel files. You cannot access those files while Excel has them open, and even if you could, Excel simply wouldn't re-read the files so your modifications wouldn't show up.
The problem you describe comes down to "I want to interact with a running Excel instance without using Excel interop". That's not going to work.

C# program runs too long mapping to an excel sheet

I have a C# program that takes a legacy report file and maps to an Excel. It was running ok but we changed the process. The legacy program groups all the detail rows together and my program breaks page rather than before when they provided all the pages. this had added to run time about 4 times as long.
I have been told that if I can manually modify Excel to create 'proper' output for input file, It can speed things up a good bit.
also go to an Excel code-behind or add-in which would run from Dxcel and thus be faster
Can someone direct me how to apply these 2 ideas?
We do the code now as an array and write the entire row rather than cell by cell.
here is copy of the code: http://www.mediafire.com/?cebg17u5wl0ir25
Automation of Office applications is generally very slow. I just encountered this problem while trying to create a complicated graphic with Visio form c# code. It lasted about 30s. Now i create a SVG-File, that is then opened in Visio. Creating the SVG-File lasts less than 1s now!
I suggest that you export your data as CSV-File and then import it into Excel. Do only the minimum, i.e. the creation of worksheets, the import of the CSV and the formatting, with Excel-automation.

Writing to Excel using Microsoft.Jet.OLEDB.4.0 + Editing at the same time

I used the code described here to update an excel sheet using c#.
The problem is that the file gets locked and cannot be edited manually while it is being updated (unlike the example code, i am doing constant updates, realtime data feed)
Since it is a trading application, operators need to be able to add excel formulas while other cells are being updated.
I am new to this and open to switch to any other technology/architecture making this possible.
I am receiving a data feed and I just want to put in an excel file and update it in realtime while making it possible for sheets to be edited manually. I guess if the dll or add-in is called from within excel rather than oledb I would not have such a lock issue. So if there is any way to call my code from excel and not the other way round (not too painstaking if possible) I welcome any suggestion
EDIT : Solution
I finally opted for RTD Technology for Excel which is exactly what I was looking for.
MS Reference is 10 years old and VBA oriented but it gives the big guidelines and things did not change much since. I think I would not have made it through without Kenny Kerr's Artcile on the subject. Many thanks to him.
You will need to integrate into Excel itself... Excel offers an interface to achieve exactly what you describe... it is based on COM and called RTD (Realtime Data-Server) and gets called from Excel.
You have to build a COM component which adheres to the official spec...
Some usfeul links to get you started:
http://msdn.microsoft.com/en-us/library/aa140059%28v=office.10%29.aspx
http://msdn.microsoft.com/de-de/library/microsoft.office.interop.excel.rtd%28v=office.11%29.aspx
http://exceldna.codeplex.com/workitem/5902 (free library to ease the development)
http://www.add-in-express.com/docs/net-excel-rtd-servers.php (commercial library to ease the development)

sending commands from excel file to a c# program

I have a program that reads Data from Excel and write data to Excel file. I need to send commands from the Excel file to the c# program (e.g. capture the F9 from the excel and get it on the c# program)
I am using Microsoft.Office.Interop.Excel framework.
How can i do it?>
the excel application interface also provides events to some excel functions, e.g.
Microsoft.Office.Interop.Excel.Application:
//
// Summary:
// Occurs after any worksheet is recalculated or after any changed data is plotted
// on a chart.
event AppEvents_SheetCalculateEventHandler SheetCalculate;
You will probably have to call native Win32 methods to add a message hook looking for a character message in the Excel window.
oferyo,
Hello. You don't mention what sorts of volume of data you need to deal with? Or the type, either (questions like: does the stuff 'sent' to the destination Excel file includes graphs or just data?).
You don't mention which version of C# you are using but you could consider calling a web service from the VBA script embedded in or added to the originating Excel spreadsheet?
MSDN article on calling WebServices from within VBA
I can't recall how to plumb VBA code into specific events on the Excel spreadsheet (like the recalculate/press of F9) but I think that should be trivial.
If you are using C# 3.5 or later you can host a WCF service within the application ... but I would suggest describing the question better because it may be the VBA->WCF/WebService->Application solution might be seriously over-engineered?
Hope this helps you think about the options you have within VBA ...
regards,
Aidanapword

Categories

Resources