Good Morning,
I have a C# agent which runs periodically and updates certain values in a particularly important spreadsheet, the reason that this spreadsheet is updated is that periodically someone will manually go into this .xls file and print screen the worksheets and paste them in to a Powerpoint presentation template as images.
These 'images' aren't charts, nor tables, simply ranges of cells that are coloured etc in the spreadsheet - and what I'm looking to do is basically automate this by customising my agent so that everytime it updates the spreadsheet, it 'print screens' a certain range that I specify and copies it as an image into the .ppt file.
I appreciate this question lacks a code example, and I'm not expecting someone to 'do it for me', any advice or pointers on how I might accomplish this would be much appreciated.
Also VSTO is not an option unfortunately (work environment).
Many Thanks
You may not have the ability to control how other people create their PowerPoint slides, but if they want a specific range of cells to update to match what the excel sheet is currently, they can Ctrl-C the section then Paste Special.
I know your question asked about automating a print screen capture of the cell range, but would this work for you? Or must there be no possibility of an accidental update, or some reason it must be an image?
The linked section will automatically update if the file is open and if it isn't it will ask if you want to update the links on opening the PowerPoint. Or right-click on the object in the slide and update link.
I've been doing it too reccently.
It might give you an idea.
Put an Alternative.Text to your shape in PowerPoint, it might help you place your new image in the correct place.
C# Paste HTML to Excel or PowerPoint
Showing HTML in PowerPoint
Related
I have a windows app that opens excel. The user can then decide to save it.
This uses Interop and is very slow when we have over 100 rows. I'm experimenting with EPPlus and see how to save directly to a file. But I don't want to do that, I need to open Excel from the app. So I'm thinking to write out the worksheet using EPPlus (thus saving time) and then copying the whole worksheet into Excel and open it. Does that make sense? Are there examples of this?
First off, I've used EPPlus and it's a great tool.
I'm a little confused by your question, so let me ask some clarifying questions.
Why are you launching excel from your app? Is it to edit some kind of file your program generates, or just random files the user wants to edit?
Once the user is finished editing the file, do you need to read it back into your app? If so, that can also be done with EPPlus.
Once I know more about what exactly you're trying to do, I'll be glad to help you.
--John
How to embed a word document into another word document via OpenXML SDK, but showing content, not an icon of word? Such, as we do it manually in word: Insert object from file -> WITHOUT checking "Dispaly as icon"?
I've found this article, but it uses an icon. I've also tried to use OpenXML SDK Productivity Tool, but shows only generated binary data.
EDITED:
I use the following code:
DrawAspect = OleDrawAspectValues.Content
and then i add image part:
var imagePart = mainDocumentPart.AddNewPart<ImagePart>("image/x-emf", imagePartId);
GenerateImagePart(imagePart);
But my image part - is just an array of bytes of word's icon.
So, in this case happens the following: when i open generated document, it shows embedded document as an icon, but when i double click this embedded document, edit it and save changes, the embedded document is shown as a content, so maybe it's possible in some way to show this content without editing embedded document? Should i use instead of array of bytes of word's icon an array of bytes of doc's screenshot?
Not sure i described it clear, so please ask
I'm afraid what you are asking for is almost impossible.
The only difference as far as the word file is concerned between the icon and the embedded file, is the image.
When you don't use a icon Word pretty much just take a screenshot of the document you are embedding and inserts that in place of the Icon graphic.
I've uploaded an example I grabbed from a Word file I made. Found this little gem in the /media folder inside the .docx file.
So basicly, your only choice in resolving this if you can't live with the Icon is to somehow grab a picture of the word-file you want to embed and insert that instead of the Icon image.
How you'd go about that can't be pretty. First of all the open xml sdk contains no such functionality. I tried playing a bit around with office interop as well, but no luck.
I only see two possible ways to achieve this.
First one is via Interop. You'll need to install a "pretend printer" like the ones that print to PDF instead of sending it to a printer. This one however needs to print to an image format. The format of the file in the Media folder was .emf but I'm not positive thats a requirement.
Anyways, should the above somehow be possible you could embed that picture, pretty much using the example you link from Microsoft, and just change this size of the "icon" which now would be an image of the document.
Second possibility would be to open the word document as a process, set the document size to 72% (or whatever makes the document be the only one on screen on your desktop) and the grab a print screen and cut it down to just the document and the use that as your image for the embedding.
For the record, I don't recommend you do any of the above, but thoose are the only options I see.
Should someone have a better solution to this I'm all ears.
Finally, should you decide that you want to push on with this, I'll be happy to code up an example of option number 2 if you reply and tell me you'd like that.
Kaspar
There is a nice wrapper API (Document Builder 2.2) around open xml specially designed to merge documents, with flexibility of choosing the paragraphs to merge etc. You can download it from here.
Using this tool you can embed a paragraph of another word document or entire word document as per your requirement.
The documentation and screen casts on how to use it are here.
Hope this helps.
At the risk of having this question downvoted into oblivion or closed as "Too Localized", I figured I would post about this issue since my boss complains constantly about it and it has me scratching my head.
We use the Infragistics NetAdvantage Excel control to create an Excel report on the fly. Some cells, we add a fill color like so:
sheet.Rows[i].Cells[0].CellFormat.FillPattern = FillPatternStyle.Solid;
sheet.Rows[i].Cells[0].CellFormat.FillPatternForegroundColor = Color.FromArgb(127, 127, 127);
This works great and the report comes out looking fine:
However, if my manager selects all the cells in Excel, copies the data to the clipboard, then pastes those cells into another Excel file, all the colors are converted into some weird 3bit palette:
Now, every Fill color is either pure red (#FF0000), pure green (#00FF00), pure blue (#0000FF) or yellow (#FFFF00). It's all or nothing of any given color. That dark grey header even becomes completely white.
One interesting thing is if I go and manually change the fill color of one of those cells in Excel, then copy and paste that, the color I manually set is copied over perfectly while the Infragistics generated cells are dithered.
This only occurs when copying between Excel files, not between Worksheets within an Excel document. Has anyone ran into this issue, or do any Excel experts know what could cause this from a technical point of view?
This is Excel 2007, and Infragistics Build 8.2.20082.1000.
This is addressed in NetAdvantage 2012 Volume 1 where there were changes to the color model used by the excel engine. Mike's reply on the Infragistics forums also mentions this.
Your best option to resolve the issue is to use the excel engine from NetAdvantage 2012 Volume 1.
So I was having the same issue and couldn't figure out why the copied format would not carry over into another worksheet. So, there is no official "fix" however, I realized that it wasn't carrying over because I was in a totally seperate Excel document. Essentially, you have to have your copy and paste document in the same Excel sheet. So, while you have the item you want to copy open, open your other Excel sheet (File, Open) from your copy sheet. Once you paste, it will now hold all of your formatting. Hope this helps!
Different versions will render colors differently and this seems to be what you are seeing
This is explained well in this article http://answers.officewriter.com/workbook-colors-are-not-displayed-as-expected-in-older-versions-of-excel
There is a tool for creating a custom palettes which should resolve this for you much easier than creating your own.
http://excelcampus.com/tools/color-palette-conversion
Excel Save preferences allows you to alter, or preserve the colors used
I've also found a solution for those not wanting (or not able to afford) to upgrade. Simply creating workbooks like so:
Workbook b = new Workbook(WorkbookPaletteMode.StandardPalette);
Will solve the problem. However, obviously you won't be able to use any totally custom colors. They'll be rounded to the nearest standard color, which was perfectly fine in our case.
Ok I think I have this one figured out after having the same problem described here and other places.......check this out! First go to the page your pasting to and Highlight the entire page, go to print area and "clear print area". Then go to the pasting area and delete the cells even if there is nothing there! Highlight the rows (even though there is nothing there). Delete the rows. Now start from scratch and copy and paste and you should be able to paste bringing over all your original colors and formulas!
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.
I have a few pdf files that were created from word or excel files.
I need to get the information thats in the tables.
The text in the document is not an image so I'm able to extract the text using tools such as pdfbox.
When I have the text I have no way of knowing what cells in the table it belongs to because I don't know where the table borders are.
Iv'e tried a few desktop tools such as abby or solid pdf converter and they are able to convert the files into nice word documents but this doesn't suit my needs as I want to be able to do this programatticly in C#.
Some of the tables have nested tables wich I think makes this a little bit more diffucult.
I appreciate your help
The difficulty here is caused by the fact that the text in the PDF is not contained within any table. It might look like it is, but underneath the surface, it is not.
So there are a couple of options that I can think of. But none of them are going to be quite as satisfying as you'd probably like.
There are some companies that offer SDKs for PDF to Excel/Word conversion. Investintech and Iceni are a couple of examples. But these solutions are not free.
If you know the exact layout of the PDF files that you need to extract the table data from, then you can use any SDK that lets you extract text from a PDF and also tells you the exact co-ordinates of the extracted text. Using this method you need to know in advance where the text is going to be, so that you can extract text from a specific area on the page. It obviously won't work if you need to process any random document.
It's a difficult task, but hopefully this will give you a starting point.