Two-way communication between Excel and my C# program - c#

I want to have a two-way communication between Excel and my C# program. When some data changes in Excel, I need to know (in real time) what changed in Excel. In the other direction, based on some events, I want to update Excel worksheet (in real time). Eventually, my program will be deployed onto a Windows Server.
Can you please suggest what are the best ways to do this?

I understand that you want to follow all changes made in a workbook. For that you might need the Worksheet_Change event as described here. You will need to set the Target argument to the area (Range,Worksheet) you're supervising. You could be able to build a log with the changes that are made to the Target ranges. The second part of your question is pretty vague, what events are we talking about ? Worksheet_Change might be the answer again but more information is needed.

Related

Importing work items into TFS from another system

TL;DR: How can I createTFS work items as a specific state?
I am trying to import our work items from our old system (Rational Team Concert). There aren't any suitable automagic tools, so I'm doing it manually. I exported everything I need into a neutral format and plan on importing them with a simple-ish C# program (Json data that has all the attributes from RTC). I've already decided how to map the info from RTC to TFS.
My problem is, how can I import TFS work items as a specific state? There is only one valid initial state. I'm not above programatically moving the state through the workflow, but that seems a bit crazy.
Thanks. I'm hoping I've missed something.
The TFS Integration Platform (which I don't recommend using) has an option called EnableBypassRuleDataSubmission (see here for more info: http://blogs.msdn.com/b/willy-peter_schaub/archive/2009/11/10/tfs-integration-platform-what-is-the-enablebypassruledatasubmission-in-the-configuration-file-question-answer-7.aspx)
This is what allows it to create WI's directly into the desired state. You should be able to use the same API's to do the same thing yourself. Note: TFS Integration Platform is Open Source I believe, so you can track down it's source and see exactly how it accomplishes it.

How to write a window service that track the number of times a specific folder was Opened

I Hope that this is the Correct way of asking this question. first my problem is that i want to know that how many times a specific folder was opened from the time my windows service start's. I don't want to write a desktop application for this purpose because i want it to happen in the background and also later i may want to add some more functionality. So that is why i need to be it a windows service.
is there some kind of OS Event that i can handle during my code, i.e the event is fired when a user open's folder.
If this is not the correct method then please let me know some other method that can help.
That's not possible in C#. You can be notified of changes within a directory and infer from that that the directory was opened--but there are many times when a directory is opened and nothing will be changed. What you're describing is most like a File System Filter Driver.
From What is a File System Filter Driver:
A file system filter driver can filter I/O operations for one or more file systems or file system volumes. Depending on the nature of the driver, filter can mean log, observe, modify, or even prevent.
Writing a filter is relatively easy, considering there are templates that you can use to base your work from. But, they do consist of kernel-mode code meaning they're not written with C# (they are typically written with C) and they are drivers.
for more details: http://msdn.microsoft.com/en-us/library/windows/hardware/ff540382(v=vs.85).aspx

How update excel file that is locked by another user

Does anyone know how to handle locked excel files with c#?
I'm trying to create an application that updates an excel file that is on the network which will be probably being used by someone when someone else will try to modify it.
So far I'm not able to write and save the file when is in use, and I'm pretty new to work with Excel and C#, so any help is welcome.
Normally, when a file is locked, you cannot open it.
Excel, however, allows you to prepare a workbook to be edited by multiple persons simultaneously. You have to prepare the workbook, and certain features will become unavailable when you do so, so this won't work for just any workbook.
Also, I don't know if you can also edit the workbook in C#, although I wouldn't know why not.
The steps needed are:
On the Review tab, in the Changes group, click Share Workbook.
On the Editing tab, select the Allow changes by more than one user at the same time. This also allows workbook merging check box.
On the Advanced tab, select the options that you want to use for tracking and updating changes, and then click OK.
The full steps and an overview of general functionality and consequences of enabling this, can be found on Microsoft's website:
http://office.microsoft.com/en-us/excel-help/use-a-shared-workbook-to-collaborate-HP010096833.aspx

How to Access the Undo Stack in Excel from C# via Office Interop?

I'm building a C# app that needs to interact with an Excel spreadsheet via Office Interop. I'd like to gain access to the full Undo stack so I can make a series of changes to the worksheet and then roll them back one at a time if necessary. I see that the Word Document object in the Interop assemblies has UndoRecord and some other niceties, including an Undo function. For example, I can call Microsoft.Office.Interop.Word._Document.Undo() with a parameter to undo multiple actions. Excel's Undo stuff, on the other hand, looks much more limited. Sure, there's Microsoft.Office.Interop.Excel._Application.Undo(), but it goes only one action deep, and if called again performs a "Redo" instead of going deeper down the stack.
I've found code online where VBA developers coded their own Undo histories for Excel because that was the only way to get the desired functionality. I don't see anything like this for C#, though. Is there any way to mimic the way Word's Interop undo works in Excel?
Alas, what's true for Word isn't for Excel. Probably because so many more people write Word VBA :). See this John Walkenbach page for what is possible in Excel VBA (and interop). Here's part of his description:
Making the effects of your subroutines undoable isn't automatic. Your
subroutine will need to store the previous state so it can be restored
if the user choose the Edit Undo command. How you do this will vary,
depending on what the subroutine does. In extreme cases, you might
need to save an entire worksheet. If your subroutine modifies a range,
for example, you need only save the contents of that range.
EDIT:
There is the Application.Undo method, but it's very limited. Here's the description from Excel 2010 VBA help:
Application.Undo Method
Cancels the last user-interface action.
Remarks This method undoes only the last action taken by the user
before running the macro, and it must be the first line in the macro.
It cannot be used to undo Visual Basic commands.
In regards specifically to Interop, I'm sure there's nothing available that's not in VBA itself.

Retrieving textBox handles

I'm currently working on a project to provide interop between two unrelated pieces of software. I need to pass the data from a textBox/textBoxes, into a textBox of the other said app.
My current idea is to find the handle of the target control, make it active, and enter the data by copying it to the clipboard, and pasting it via:
Clipboard.SetText(textBox1.Text, TextDataFormat.Text);
SendKeys.SendWait("^V");
As textBoxes have no 'caption', handles are dynamically assigned on the process start, and class names are appended with various data regarding the process, is it possible to get a handle for an object within a window via some sort of indexing? I'd be more than willing to find the correct handle by trial and error if need be, as long as it would be consistent for every instance of the application.
Thanks in advance
A.
If you don't have any other choice.. to make this easier, you can use AutoIT.. I had to do something like this a very long time ago. AutoIT. They have a DLL for .net Applications, so you can use their functionality without having to use their scripts. If you do use their scripts.. they also have an option that will turn their script into an executable.

Categories

Resources