ODF Toolkit: Get string value from cell without the comment from ods or odf dodument - toolkit

ODF Toolkit provides the method getStringValue() to get the cell string content. If the cell has or even had a comment the getStringValue() returns the existing or former existing comment + the cell content.
Cell cell = column.getCellByIndex(0);
String value = cell.getStringValue();
How do i get only the cell content without the comment?
Example output ('PDF' is the visible cell content):
2014-03-04T00:00:00
kair
media/Dateiname.pdf
PDF
Workaround is parsing the 'value' which is not error proof.

yesterday I was struggling with the same issue and my colleague came up with an answer:
Cell cell = column.getCellByIndex(0);
String value = cell.getOdfElement().getLastChild().getTextContent();

Related

Get value of same cell from multiple sheets

I'd like to get the value of cell A1 from multiple tabs in my sheet. I attempted to use INDIRECT, only to be reminded that it wouldn't work in an ARRAYFORMULA. Is there some sort of "makeshifty" formula that would do the same thing?
This is what I originally attempted:
=ArrayFormula(IF(LEN(A2:A),INDIRECT(A2:A&"!A1"),))
Column A is a select list of the tab names in my sheet. So the first instance works, but of course, it doesn't populate down the column as I had hoped. I realize I can just copy the formula down the column, but some type of an ARRAYFORMULA would be ideal as I add rows to the list.
I found this answer, but don't see how I could apply it to my situation.
I also found this answer, but thought since it's 2.5 years old, maybe someone has discovered a clever way to avoid the drag of copying.
Answer:
You need to do this with a script or by using the drag method - INDIRECT uses a string reference and so can't be used with an array.
More Information:
Unfortunately for the user of INDIRECT with ARRAYFORMULA, a discovery of a clever method isn't the issue - the limitation of what can be done with only formulae that is the root of this problem.
Setting up a custom function:
From the Tools > Script editor menu item, you can create scripts. An example custom formula that you could use would be as follows:
function ARRAYINDIRECT(input) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
return input.reduce(function(array, el) {
if (el[0]) array.push(el[0])
return array;
}, []).map(x => ss.getSheetByName(x).getRange("A1").getValue());
}
Make sure to then save the script with the save icon.
In your Sheet you can then call this custom formula as so:
=ARRAYINDIRECT(A2:A)
Rundown of the function:
Takes the input range from where the formula is called - in this case A2:A
Reduces the input to remove all cells that are empty
Maps the name of the sheet which is stored in the cell to the value in A1 of the sheet it references
Returns an array to output
References:
JavaScript Array reduce() Method
INDIRECT - Docs Editors Help
ARRAYFORMULA - Docs Editors Help

vba: getElementsByClassName with different class names

I am working on an excel sheet, which collects data from a website. A few words about this website:
- it is independant from me, I can not change its struckture
- it should look like a table, but it is not. The structure is like this:
<h4>blabla</h4><span class="address">blabla</span><span class="state_x">blabla</span>
<h4>blabla</h4><span class="address">blabla</span><span class="state_x">blabla</span>
<h4>blabla</h4><span class="address">blabla</span><span class="state_y">blabla</span>
The trick is the "state_?" class, its name can change (but only the end of it).
What am I doing now?
- collect all the data into arrays
- of course I will get "state_x" and "state_y" arrays
- go through the arrays, and write everything to a sheet
The problem:
When I get to the "state_?" arrays, I already don't know, where its data came from.
The best would be to have only one "state" array, which can collect data from any "state_?" classes. Of course this code doesn't work, but to show the logic:
Dim state As Variant
Set state = ieApp.Document.getElementsByClassName("state_*")
How could this work? Any help is appreciated, please consider, that I am new in vba.
NEW INFOS
I have found some further help by analysing the source HTML code. Each row is nested in a <div class="listitem"> </div>. Is it possible to create an array, where each element is a complete "listitem" div, and with a for loop extract the data from these elements, as written above?
Each "listitem" div can contain only one "state_?" class. So this way I wouldn't loose the information, where the data comes from.
Try querySelectorAll with selector e.g. "*[class^='state_']" which should select all elements which have class name that starts with text state_. More about selectors here. HTH
Dim states As IHTMLDOMChildrenCollection
Set doc = ie.document
Set states = doc.querySelectorAll("*[class^='state_']")
If (Not states Is Nothing) Then
Dim i
For i = 0 To states.Length - 1
Debug.Print states(i).innerHTML
Next i
End If

Converting array element to string in VB (using Visual Studio 2015)

So I'm trying to set up a VB Windows Form that reads data from an array and displays it in a label (and sometimes textboxes so it could be edited). The array contains strings and I know they are stored properly because I can make them appear properly when using MsgBox.
For example
MsgBox(ArrayName(0,0))
works, but when I use
textboxname.Text = ArrayName(0,0)
I get a build error. I thought adding ".ToString" at the end might solve this, and the build error is gone, but then the textbox says "System.Char[]" instead of the value that I put inside the array. The MsgBox shows this as well, if I put ".ToString" at the end.
Thank you in advance for your help!
Edit: The array is declared via the code:
Module ModuleName
Public ArrayData(20, 6) As Array
End Module
so that I can edit it outisde of any specific subroutines.
The array only contains the characters (delimiter is comma): 0,1,2,3,4,5,6 in the first row and q,w,e,r,t,y in the second row.

Angular.js - using NG-Grid, how to get the length of value inside cell. Nothing seems to work

I am new to Angular and NG-Grid and trying desperately at a new company to get up to speed on it.
Using NG-grid for Anugular.js is there a way to format a cell using custom cell template if a cell contains more than x number of characters. I've search the web and their API and examples but cannot find an answer to this one. For instance if a cell has more than 40 characters make the background of that cell red. It doesn't seem to like the .length() function for comparison some reason.
This works great:
{green: row.getProperty(col.field) > 30}>
But this doesn't
{green: row.getProperty(col.field).length() < 40}>
AM I using the .length function wrong here or can it even be used inside ng-grid cells?
How do you get the length of the value inside a cell?
Here is a basic PLNKR based on their simple example.
http://plnkr.co/edit/fCUpoZ81vxFgt9sBHznz
Thanks
Use length instead of length() function. Its a string property not a function.
http://plnkr.co/edit/8KB8Rje0wNc2OpyUwOYZ?p=preview

How to paste tabular data into the "new row" of a DataGridView with AllowUserToAddRows set true?

We use DataGridViews throughout our UI... most are data-bound to some backing table... most of those through a BindingSource.
They all have supported Ctrl+C to Copy tabular data out (so you can paste into Excel or Word tables, etc.). That was easy... it's built-in... just set MultiSelect true and ClipboardCopyMode to EnableWithAutoHeaderText (or one of the other Enable... settings).
Our users have requested us to similarly support Ctrl+V to Paste tabular data copied from Excel etc. Unfortunately, that is not nearly so easy. I created a generic utility method PasteStringTable(DataGridView) that will pull the tabular data off the Clipboard and then paste it into the selected cells of the argument DataGridView. I have that working except for one key issue:
If the DataGridView has AllowUserToAddRows set true, and the user is in that magic "new row" at the bottom, then I wanted to add rows for each row on the Clipboard. But the problem is, nothing I do programmatically ever seems to get it to actually add that row... I've tried everything that I can think of (or find via Bing or Google):
(1) I tried doing BeginEdit / EndEdit on the DataGridView.
(2) I tried first setting the DataGridView.CurrentCell to the cell I was about to edit, then DataGridView.BeginEdit(true), then edit the cell by setting its Value property, then DataGridView.EndEdit().
(3) I tried doing #2, but where I did SendKeys.Send(value) instead of .Value = value.
(4) I tried doing DataGridView.NotifyCurrentCellDirty(true) in the middle of the above.
(5) I tried modifying the underlying data source first by manually doing DataGridView.Rows.Insert(index, 1) to try to force in a new row before I pasted into it... but that throws an exception since my DataGridViews are data-bound. (NOTE: I do not want to hard-code specific access to the underlying data because I want it to work like Paste where the data copied lines up visually with the DataGridView's columns.)
(6) Many other variations...
In the end, most attempts result in the same behavior: you can see that the bottom row gets modified... you can see the first row of the data you copied show up in that magic "new row", until you click out of the row and the row goes blank again... unless you manually edit it, it never gets added to the underlying data. Even if I try doing SendKeys.SendWait(...), it still doesn't act like it would if I typed in that data.
How do I programmatically get that magic "new row" to act like it would if I typed in the pasted in data??
(Surely I am not the first person to want to paste tabular data into DataGridViews.)
After much trial and error, this is the pattern I came up with that works well in most cases. This is pure guesswork, though, so if anybody knows how it is supposed to work, please let us know. Anyway, here's what I've got working:
DataGridViewCell cell = dgv[colIndex, rowIndex];
if (!cell.ReadOnly) // && (evenIfNotSelected || cell.Selected)) // Selected is not stable in some cases
{
if (!cell.OwningRow.IsNewRow)
cell.Value = cellData;
else
{
dgv.CurrentCell = cell;
dgv.BeginEdit(true);
dgv.NotifyCurrentCellDirty(true);
//SendKeys.SendWait(cellData);
cell.Value = cellData;
//dgv.CommitEdit(???);
dgv.EndEdit();
//PSMUtility.DoMessages();
// Do it again to try to overwrite the default value that might get injected by EndEdit adding the row
cell.Value = cellData;
}
}
Also i try many solution and finally it's work in my case.
private void calculationGrid_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar == 22 && Control.ModifierKeys == Keys.Control)
{
calculationGrid.CurrentCell.Value = Clipboard.GetText().Replace("\r", "").Replace("\n", "").Trim();
calculationGrid.BeginEdit(true);
calculationGrid.NotifyCurrentCellDirty(true);
calculationGrid.EndEdit();
}
}

Resources