Determining Excel BG color in C# - c#

I need to write an app in C# that opens an Excel file which has rows that have either ayellow, blue or just the plain white background color, then only returns the values in Column 'A' that does NOT have a white background(just yellow or blue values in Column A should be returned).
I found code on SO to get the data from the Spreadsheet, but I don't have any info on the background color.

I can confirm, Chris Walsh's answer is good. Definitely use the Microsoft Office Primary Interop Assemblies:
http://www.microsoft.com/download/en/details.aspx?id=3508
You can also take the road of Visual Studio Tools for Office but I recommend the former, it's easier and cleaner.
Here's another code example that shows how you can SET a cell color, so you have a good sample of how to access that property.
http://forums.asp.net/t/1310118.aspx/1?Changing+Cell+color+of+excel+sheet+programatically+

Related

Adding a note to a cell in Google Drive spreadsheet using C#

I'm currently working on a C# program to write a set of test results to a spreadsheet on Google Drive, and under the current format the cell to which I'm writing has one data value in the cell and the other 5 in a note (not a comment) on the cell.
EX: 1.8 visible in the cell, and when the cursor hovers over said cell, a small box appears to the side containing
Average: 1810 ms
Highest: 1921 ms
Lowest: 1708 ms
StdDev: 78 ms
Median: 1787 ms
My program currently can access and write to the cells in the Google spreadsheet, but I can't find a way to create a note for the cell and write to that. Any help is welcome.
If you take a look at this, setting a comment in the described way will actually add a note to the cell. This might be a known issue for them but I guess works in your favor. Hope this helps. :)

Font classes and switching between them

So, I have text entered in textbox, which I need to show as preview in label. Problem is, it has specific formatting, so #A is trigger for red color, and text is red colored util some other text color sign is inserted (like we at some point insert #B and text is green from that point, and so on).
That wouldn't be big problem if there weren't two problems:
Obviously this is web application, and although is written in C#, many things that can be done on windows forms, can't be done here.
Bigger problem, that I can't solve is that I also have signs for text background and for text hight (which I would solve in classes).
font color red_____________green___________blue__________
font bacgr. black_________________________________red_____
font hight normal_________________double_________________
I hope you get it, I have three groups of parameters (font color, background color, and text hight) and parameter from one group should change one property, and others should stay.
This is sure complicated, but at least I would need idea how to make that for example #A triggers that color of text in Label becomes red, and that #A is deleted, and when after that is for example #B, at that point text becomes green, and so on.
Have in mind that this is ASP.NET, so many C# features are not available.
The simplest way to accomplish this would be parse the string for your tags and replace them with equivalent HTML/CSS tags (<span class="red">) that implement the formatting you want.

Excel colours getting distorted when being copied from one template to another using VSTO(C#)

We are trying to generate an excel sheet using a template. Normally we would have done have a basic "Save As" to save the file but the file size came up to be too high. So, now we're working on copying the used range of the original workbook to a new workbook.
The data is getting copied, along with the validations and formulae on using the PasteSpecial command, and all data and formatting is the same, other than the cell background and the font colours. They have almost inverted.
Please suggest how could i solve this.
Excel use colors from a palette of 56 colors (may be more in Excel 2007/2010) that can be changed using Tools/Options/Color.
You can copy colors from one workbook to another using:
Workbook1.Colors = Workbook2.Colors
By copying the palette, you will of course affect the colors of all UI elements in the target workbook, not just the range you're copying.
It worked this way, the propety Workbook.Colors wasn't there. The foolowing statement did the job for me
wb2.set_Colors(Missing.Value, wb.get_Colors(Missing.Value));
Thank you for the replies everyone.

Report loses color when exporting to Excel

I have a local report in a WinForms application that is giving me some trouble. On this report, I have a table and I am trying to change the BackgroundColor of the Detail row.
When I change it to "Red" and view the report, the row is Red as hoped for. When I export the report to Excel and PDF, the row is Red, too. So far, so good...
If, however, I change the row color to something like "DarkSeaGreen," it will display in my ReportViewer control ok and the PDF looks good, too, but the copy I exported to Excel just shows this row as gray.
I have tried out a few different colors... some work, some don't. I have also tried setting this property different Hex values; again, some work, some don't.
Has anyone experience this before? What is causing the colors to turn to gray when the report is exported to Excel?
Any assistance is greatly appreciated!
Edit: Also, the same colors that don't display in Excel don't print from the ReportViewer either... looks like Excel isn't the main culprit.
Have you tried using a hexidecimal value for your colour and see'ing if Excel picks it up. My guess is that Excel doesn't support the CSS colour naming codes.
Select your row, table, text box etc and set the colour to something like #2f4fa2 - see if that works in Excel.

Format Excel Chart Background using C#

I can already populate the data into the spreadsheet, create the chart based on the range I select. However, when it comes to formatting the actual chart I feel a bit lost as their are so many options!!
It is an xlCylinderBarStacked type chart. I simply need to make the color of the bars a nice light orange and make the background a light blue fading into white at the bottom.
Any idea's how to do this?
Just to close this question off. I played around a little with the properties and the following achieved the gradient effect on the background of the chart.
xlChart.Interior.Color = ColorTranslator.ToOle(Color.LightSkyBlue);
chart.ChartArea.Fill.TwoColorGradient(
Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal,
1);
One good trick with Excel and other VBA-enabled apps is to manually create the formatting/content you require using the Excel GUI, whist recording a 'macro'. Once this is done you can then inspect the generated VBA to see how to use the API to acheive the same results programmatically. You will of course have to do some translation from VBA to C# but essentially the same methods should work.

Categories

Resources