WrapText- Auto format cell height - excel

I am using OpenXML to create reports, I am filling data in existing excel template file.
In excel template 'Wrap text' for all cells is set to true. When my report is complete I open excel file.
In opened file cells are not sized correctly with text wrapping (text wrapping is not applied). Also I observed on machine with office 2007 it works cell are wrapped but on office 2013 cell are not correctly wrapped. If I just double click on any cell then entire row is correctly updated.
Can someone please help me in this, is any property \tag I can set in openXML so that on document open cells are correctly shown.
Previously we were using OLE office interface there it works always so expectation is it should work with openXML too.
Thanks,
Dhanaj

Related

Detect Strikethrough in Excel Cell with VB.NET on a Windows Forms App

I am currently writing a program in windows forms with vb.net and an SQL back end. The program is taking customer created Engineering Change Orders, Bill of Material updates, and recreating a custom template that we upload to our Oracle system to create the BOM changes. The customer sends us an excel spreadsheet with the updated BOMs. Items added to the BOM appear in red text and items being removed from the BOM are in red text with a strike through the text. My program is reading down the excel column and adding the item numbers to an SQL table that holds all the new BOMs. My problem is the removed items, items that appear in red with a strikethrough the text, are also being added. I need a way to detect if the font has a strike through so that I can stop them from being added to the SQL table. However, I can't find any way to detect text formatting on the excel sheet. I know you can detect text formatting with VBA inside of an excel macro but I can't find anything on how to do this with VB.NET on windows forms apps.
I thought the code would look something like this however "Characters" is not a legitimate option here.
If xlworksheet.cells(1,1).characters.font.strikethrough = true then
next
end if
Is there anyway to detect text formatting options like strikethrough with VB.NET inside windows forms.
We can use excel interop to do this. We can look for Font.Strikethrough. The following code worked for me.
Dim range as excel.Range = xlworksheet.cells(1,1)
If range.Font.Strikethrough = true then
'Strike through detected, do something
else
'No strike through detected, do something else
End If
The above code looked at the excel cell (1,1) or A1 and checked to see if it had a strike through or not. I confirmed this solution by applying a strikethrough in text on this cell and resaving the file and running the code again without a strike through.

How to retrieve excel cell formatting properties in app-for-office add-in

I'm starting to play around with apps for office - specifically working on a task-pane app for excel that needs to retrieve cell formatting properties from a range.
It is possible to set properties in a bound table with
bindingObj.setFormatsAsync(cellFormat [,options] , callback);
but an equivalent getFormatsAsync() doesn't appear to exist. Anybody know how to do this?

save text from textbox in visual studio to excel cell

I have few Textboxes in my form and I want to save the data they Contains into excel.
How can I make new excel file and save the data to the excel cell?
How do you determine what information will be transferred to each cell in Excel?
Thank you all
p.s
I'm using Visual Basic with Visual studio 2013
If you're in excel vb and you're in the form code, you can do this:
thisworkbook.worksheets("Sheet1").range("A1").value = me.textBoxName.value
It'll copy whatever is in the textbox to sheet1 of the current workbook in cell A1.
You can play around with it to customize it to your needs. Outside of the form, you'll need to replace me with the form name.

drop down list compatibility issue between Excel 2007 and Excel 2010

I prepared a spreadsheet where I used the drop down list command in several cells (data validation, list). I needed to provide two versions of the same spreadsheet: one saved as Excel 2007 file, and the other one as Excel 2010 file.
If I open the Excel 2007 file with Excel 2010, in the cells where I inserted the drop down list, the reference to the cells that contain the list is somehow changed and the drop down list shows the wrong data.
For example, if I specify to use as the data in the list the values of cells C20:C25, when I open the file with Excel 2010 the cells are changed to D15:D20. I did not find a trend in the "shifting" of the referenced cells.
How do I prevent this without using Excel 2007 for the 2007 file only and Excel 2010 for the 2010 file only?
I have found a workaround that works for me.
If this is your original dropdown box formula:
=Sheet2!A1:A5
Then change it to:
=INDIRECT("Sheet2!A1:A5")
For me, this stops it removing the dropdown when opening in Excel 2007 after saving in Excel 2010. I found this out accidentally because I needed INDIRECT to define my dropdown range, as it varied.
Jeremy
I found the answer here: http://www.ozgrid.com/forum/showthread.php?t=150080
"If your dropdown is a data validation list and you have used a list on another sheet as the
source, then you need to do what Tayt said, since versions pre-2010 cannot refer directly to
a range on another sheet and the validation will simply disappear."
That solved my problem; hopefully it'll solve yours.
You are opening a 2007 file with 2010, saving it and closing it. Perhaps 2010 is automatically converting your file to the 2010 format.
Have you tried intentionally telling 2010 to save your file in the 2007 format?
I solved this by having both Excel 2007 and 2010 installed.In Excel 2010 I selected the cell that should have contained the dropdown-list and then pressed data validation from the data tab. I just copied the values in excell 2007 and saved.
If you find the sheet to be protected, you can use this solution : http://mcgimpsey.com/excel/removepwords.html
Hope it helps

Fonts look different when inserting Excel table in a Word document

I am trying to use a VBA macro (for Office 2003) to do the following:
In Excel, the user will select a range of cells
In Word the user will call the macro (via a button or shortcut) to insert the selected Excel range as an embedded object
The code is not the problem so far, my problems are:
Given that the user is working in a Word document, most likely will use the same fonts in Excel
When Excel range was inserted in Word and they both use the same font names and sizes, they look different inside Word ( fonts look as if they stretched a bit)
Styling Cell borders in Excel is not like styling cell borders in Word
I do appreciate any advice on this regards
When you paste as an Excel Worksheet Object, what Word is actually displaying is an image created by Excel. Notice that you can't select any text, for example. Word appears to be distorting the image ever so slightly, so that the fonts won't line up.
Edit: I can't speak for Office 2003, but Office 2007 defaults to the HTML format using PasteExcelTable. The exact macro statement is
Selection.PasteExcelTable False, False, False
This will give formatting that is compatible with Word, but unfortunately the data is not live and won't get updated as the spreadsheet is changed. If your requirements don't include live update, try this method.
Is it possible to have the macro creating a table out of the cells (as normally happens when you manually copy them), rather than inserting an Excel Object.
The best visual results results can be achieved by using Selection.CopyPicture(Appearance, Format); however, you will not be able to edit the data inside Word as you will only get a picture.

Resources