Spreadsheetgear .find method - asp.net

Tools: asp.net VB, SpreadsheetGear 2010
I need to read in Excel files from external users and I do not control the format. There are 3 sections of data. I am able to read in the header. The challenge is that the body details can contain an infinite number of rows, and sometimes those rows are blank. I can determine the footer row because there is a piece of text that is unique. Therefore I can perform the following:
Dim dFoot As SpreadsheetGear.IRange = worksheet.Cells("20:21").Rows
Dim rngDet As SpreadsheetGear.IRange
rngDet = dFoot.Find(what:="UNIQUE TEXT HERE",
lookIn:=SpreadsheetGear.FindLookIn.Values,
lookAt:=SpreadsheetGear.LookAt.Whole,
searchOrder:=SpreadsheetGear.SearchOrder.ByColumns,
searchDirection:=SpreadsheetGear.SearchDirection.Next,
matchCase:=False,
after:=dFoot)
Unfortunately, I am now stuck here. I cannot determine where the cell is (i.e. V79) or how to move 7 columns over and 3 down to get the first value for inserting. I have tried offset and different methods of reading the rngDet, but no luck. I have also tried rngDet.Activate() to read the active cell, but it does not work the same as Microsoft.
I appreciate any help you can provide.

Tim, Thank you for your questions. First time asking so I probably was not very clear. I did find the answer for myself today. I have a group of cells that I need to upload. The problem is that they will be moving up and down the page depending on how many rows were entered in the section above. I realized that I did know what column it was going to be in so I performed the following:
Dim x As Integer
Dim xFooter As Integer
Dim columnnumber As Integer = 21 'Column V
txtTest.Text = worksheet.Cells.RowCount
For x = 500 To 1 Step -1
If worksheet.Cells(x, columnnumber).Value = "TOTAL PRODUCT COST CALCULATION" Then
txtTest.Text = x
xFooter = x
Exit For
End If
Next x
I am now able to use my x value as the left hand corner of my group of cells. I know that the values go over 7 columns from here and down 20 rows which gives me my quandrant of values.
Thought I would share just in case anyone has the same problem.

Related

VB.Net - How to compare 2 columns in GridView as numbers?

I have a GridView which I plan to add different colors in each row based on certain conditions.
One such condition is to color the row in a specific color if a number in column 6 is higher than the number in column 7.
If e.Row.Cells(6).Text > e.Row.Cells(7).Text Then
e.Row.BackColor = ColorTranslator.FromHtml("#FDD533")
Else
However, when I test the code it seems to only change the color when the left most value in column 6 is larger than column 7, regardless of the fact that column 6 is in the hundreds, while column 7 is in the thousands.
I believe the cause is coming from me using text in the If statement. However, any instance of number I can think to change doesn't seem to fit into the code:
If e.Row.Cells(6).Number > e.Row.Cells(7).Number Then
or
If e.Row.Cells(6).Integer > e.Row.Cells(7).Integer Then
These example gives me a message saying
'Number' is not a member of 'System.Web.UI.WebControls.TableCell'
What else can I use that is compatible with the current code?
I believe that you are missing a casting. I'm not sure if you're comparing only Integers or complex numbers, if you don't know I recommend you to cast directly to doubles:
If Convert.ToDouble(e.Row.Cells(6).Text) > Convert.ToDouble(e.Row.Cells(7).Text) Then
e.Row.BackColor = ColorTranslator.FromHtml("#FDD533")
Else
Convert.ToDouble will convert any text to number.
More info about casting:
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-convert-a-string-to-a-number
https://www.dotnetheaven.com/article/casting-integer-to-long-single-and-double-using-vb.net
If you might have some empty values you can use the TryCast:
https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/trycast-operator

How to Add Column (script) transform that queries another column for content

I’m looking for a simple expression that puts a ‘1’ in column E if ‘SomeContent’ is contained in column D. I’m doing this in Azure ML Workbench through their Add Column (script) function. Here’s some examples they give.
row.ColumnA + row.ColumnB is the same as row["ColumnA"] + row["ColumnB"]
1 if row.ColumnA < 4 else 2
datetime.datetime.now()
float(row.ColumnA) / float(row.ColumnB - 1)
'Bad' if pd.isnull(row.ColumnA) else 'Good'
Any ideas on a 1 line script I could use for this? Thanks
Without really knowing what you want to look for in column 'D', I still think you can find all the information you need in the examples they give.
The script is being wrapped by a function that collects the value you calculate/provide and puts it in the new column. This assignment happens for each row individually. The value could be a static value, an arbitrary calculation, or it could be dependent on the values in the other columns for the specific row.
In the "Hint" section, you can see two different ways of obtaining the values from the other rows:
The current row is referenced using 'row' and then a column qualifier, for example row.colname or row['colname'].
In your case, you obtain the value for column 'D' either by row.D or row['D']
After that, all you need to do is come up with the specific logic for ensuring if 'SomeContent' is contained in column 'D' for that specific row. In your case, the '1 line script' would look something like this:
1 if [logic ensuring 'SomeContent' is contained in row.D] else 0
If you need help with the logic, you need to provide more specific examples.
You can read more in the Azure Machine Learning Documentation:
Sample of custom column transforms (Python)
Data Preparations Python extensions
Hope this helps

How to read /manipulate input in ADA?

Reading from standard input, I want to be able to insert a few sets of integers like so and do some math on every 2 integers.
I.E:
"Hello enter some numbers to get their sum":
1 9
2 10 [enter]
OUTPUT:
1 + 9 = 10.
2 + 10 = 12.
I have been successful with only the user being able to enter only 2 integers as I just do
get(numOne);
get(numTwo);
and then something like:
answer := numOne + numTwo;
put_line(answer'img);
But I am new to ADA and don't know how I can scan through all four of the integers I used in my example and only sum the first two then the second two, and if there is more then keep summing them up by two's. Essentially the program would first scan through all the user input and do math on every two integers and keep concatenating them to a result string that we can print at the end. I know how to do it, I am just new to the language and don't how to put it in code. Please ask if you need more info. All help is appreciated.
Just put a loop around your existing logic. - And notice that Ada has nice "infinite" loops. :-)

VBA remove formula and leave original value

I have a spreadsheet called "MTM Lookup", this is downloaded from a specific site, in column D of this spreadsheet are values, but these values have a formula attached to them. The formula rounds these values to 0. The formulas don't round on a specific cell. They look like this =ROUND(35370.6708773751,0) or =ROUND(48368.0427161566,0). I need the values to come through with all the decimals or rounded to 10 decimals but cannot get this to happen, I can remove the formula and leave the value but it is rounded to zero. Please could anyone assist with some simple vba to either remove the =round(,0) or replace the 0 to 10 ie round(x,10).
I don't see any problem in the formula you provided.
When I put
=ROUND(35370.6708773751,0)
to a cell, I correctly see 35371 in the cell.
There are, however, two things in play here.
Formula
Cell Format
For example, when I enter the following value to the cell:
=ROUND(35370.6708773751,10)
I do see 35370.67088 as a result (after rounding to 10 places, cell format rounds it again to 5 decimal places)
I don't know why entering the value without any formula shows you 0, but this leads me to the same suspscion, i. e. that the problem is in the cell format.
You can check it by right clicking on the cell > Format Cells (in office 2010 at least) or programatically, using the following, for example:
sheets("MTM Lookup").range("A:1").numberformat = "0.0000000000"
Hope that it helps.

Strange QTableWidget behavior - not all cells populated after sorting followed by repopulating

I have a QTableWidget that I populate like this:
// Clear the table
this->topPatchesTableWidget->setRowCount(0);
this->topPatchesTableWidget->setRowCount(numberToDisplay);
for(unsigned int pairId = 0; pairId < numberToDisplay; ++pairId)
{
// Display patch match scores
QTableWidgetItem* myLabel = new QTableWidgetItem;
myLabel->setData(Qt::DisplayRole, myValues[pairId]);
this->tableWidget->setItem(pairId, 0, myLabel);
... fill other columns ...
}
(I have some other UI elements to set properties that compute the values in myValues). If I change the properties, recompute, and recreate the table, everything works as expected. If I sort the table by clicking on one of the headers, it sorts correctly. HOWEVER, if at this point (after sorting) I click my button again to recompute the values and recreate the table, the table is very broken. That is, many of the cells are empty, and the cells that are not empty don't seem to be in any particular order.
By adding a manual call to
this->tableWidget->sortByColumn(0, Qt::AscendingOrder);
at the beginning of my CreateTable function, everything works as expected, but of course the newly created table is sorted by column 0 rather than the column that was selected for the last sort.
Does anyone have any idea why things would go so wrong without the call to sortByColumn? (I tried to make a simple example but I can't replicate the problem in a demo program).
Thanks,
David
I had a similar problem in python, if a column header was selected to enable sorting the cells after that column stopped populating.
I got around it by setting self.tableWidget.setSortingEnabled(False) at the beginning of the row add method, then setting it back to self.tableWidget.setSortingEnabled(True) at the end of the row add method. According to riverbank computing this is the officially recommended way to address this problem.
QTableWidget.setItem (self, int row, int column, QTableWidgetItem item)
Note that if sorting is enabled (see sortingEnabled) and column is the current sort column, the row will be moved to the sorted position determined by item.
If you want to set several items of a particular row (say, by calling setItem() in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. setItem() will not move the row).
See also item() and takeItem().
This is an elaboration on Karnisov's answer, also with PyQt. Disabling sorting before doing any setItem()s also worked for me, but it caused the user's sort selection to be lost, so I did it like this, where t is a QTableWidget:
oldSort = t.horizontalHeader().sortIndicatorSection()
oldOrder = t.horizontalHeader().sortIndicatorOrder()
t.setSortingEnabled(False)
# make the changes
t.sortItems(oldSort, oldOrder)
t.setSortingEnabled(True)
Note that it is still possible for the sort to change slightly with this code. This appears to be because the sort that Qt is using here doesn't move any items that were already in order, so if we had a table like this:
NUMBER LETTER OTHER LETTER
1 B C
2 G Q
3 A Q
If we sort by NUMBER, then by OTHER LETTER, nothing changes. But if we sort by LETTER, then by OTHER LETTER, we get:
NUMBER LETTER OTHER LETTER
1 B C
3 A Q
2 G Q
So if we had previously sorted by LETTER, then OTHER LETTER, this code would only do a single sort by OTHER LETTER, and we'd end up with the second version of the table instead of the first (assuming that the order the elements were added to the table in matches NUMBER). In this spot in my code, all items are deleted and re-added to refresh the table, so this can sometimes cause noticeable changes in order.
I had the same problem - always, when I wanted to insert new data, i buildet the header and setSortingEnabled(true). I guess the QTableWidget does not like several calls for setSortingEnabled(true). So I put it into the constructor of my MainWindown, and thats it!
I never figured out what was wrong with this. I gave up and implemented a custom model/view which is probably a much better idea anyway.

Resources