Search for last value in specific column - c#

I am using Excel Interop in C# to read from a Excel Sheet.
My Excel Sheet has always the same Structure:
| A | B | C | D |
1 | | | | |
2 | Text | Text | Text | Text |
3 | | | | |
4 | Text | Text | Text | Text |
5 | Text | Text | Text | Text |
6 | Text | Text | Text | Text |
...| ... | ... | ... | ... |
75 | Text | Text | Text | Text |
76 | | | | |
77 | Text | | | |
78 | Text | | | |
79 | Text | | | |
What i now want to get, is that start and end row of my required data. In the example above it would be "4" for the start row and "75" for the end row.
The start row is no problem: i get it using Range.Find("text").Row because i know the first entry of my data.
The problem is getting line 75, because the function .End always gives me the very last cell of the sheet. This would be 79 in my example.
I could loop form row 4 to 76 and check if cell is empty but this does not seem to be very smart and efficient.
Is it possible to ask for example for the last not empty cell in column D? This would solve my problem.
Hope this was not too confusing...
Best Regards and thanks in advance,
Julian

"Is it possible to ask for example for the last not empty cell in column D? This would solve my problem."
Maybe this solution will be good for you. It finds first blank element, but I think you could edit it:
first blank row in excel

Related

Openxml excel c# does the row has merged cells

I have a spreadsheet which has two rows with three columns,
--------------------------------------
| title | id | roles
------------------------------------------
| DOC | 1 | pediatrician
-----------------------------------------
| NURSE | 2 | A&E
| | | pediatrics
| | | orthopedic
-----------------------------------------
| DOC | 3 | orthopedic
-----------------------------------------
In which row 2 (NURSE ) column 3 (roles) have a merged cell
using C# (openxml) I want to read column (roles) as one single values
can some one help?

WPF Datagrid or maybe something else that can have indents in the first column?

I have a table with a bunch of data this is a small sample:
Header - Object name
Waarde
ExportRoot.a80_02_00_01_Status.Settings.Off
0
ExportRoot.a80_02_00_01_Status.Standby
0
ExportRoot.a80_02_00_01_Status.Cooling
1
ExportRoot.a80_02_00_01_Status.Drying
0
ExportRoot.a80_02_00_01_Status.Heating
0
ExportRoot.a80_02_00_01_Status.PrepDrain
0
I wish to style this table in a way to where its more readable by removing the object parts and indenting the table like how it looks below.
| Header - Object name | Waarde |
|--------------------------|---------|
| ExportRoot | |
| | a80_02_00_01_Status | |
| | | Settings | |
| | | | Off | 0 |
| | | | Standby | 0 |
| | | | Cooling | 1 |
| | | | Drying | 0 |
| | | | Heating | 0 |
| | | | PrepDrain | 0 |
Is there a way of doing this and if so what should I be looking for all I've found so far are tables with sub tables and that not exactly what I'm looking for. If anyone has an idea let me know I'm super lost.
So basically you need a TreeListView:
There is one project on CodeProject that you can check:
WPF TreeListView Control
There is also commercial products, like DevExpress:
DevExpress TreeList View

i want my datagridview 1st n 2nd column to be fixed n remaining columns should be enter by user

|BrandName| ML | STOCK |
| | | |
|PEPSI | 100 | |
| | | |
|LIMCA | 200 | |
| | | |
I Want my DataGridView to look like above table.
and how to save the data after entering stock.
You have a Frozen property for each column of the DataGridView. You juste have to set it to True.
dataGridView.Columns[0].Frozen = true;
dataGridView.Columns[1].Frozen = true;
Would've been pretty easy to Google up, don't you think?

Creating editable table from multiple sql database tables in ASP.Net

I have a problem with displaying and editing some data from database to ASP.Net webpage.
Data from database consist from few different tables:
Table Files, witch contains file_id and a file name
| file_id | file_name |
--------------------------
| GUID | VARCHAR |
file is saved in database as a collection of lines for one file_id,
Table Items,witch contains basically all the lines from all the files
| item_id | file_id | step | number |
---------------------------------------------------
| GUID | VARCHAR | BIGINT | BIGINT |
Table Wording, witch contains all distinctive wording
| wording_id | wording_eng | description |
-----------------------------------------
| GUID | VARCHAR | VARCHAR |
And M_N_table witch contains connection between items and wording
| item_id | wording_id |
----------------------------
| GUID | GUID |
my final display table should look like this and should be editable
| | file1 | file2 | file3 |.........| fileN | | |
| sortorder --------------------------------------------------------------------------| wording_eng | desription |
| | step | number | step | number | step | number |.........| step | number | | |
------------------------------------------------------------------------------------------------------------------
| 1 | 10 | 15 | | | | |.........| | | something1 | something2 |
------------------------------------------------------------------------------------------------------------------
| 2 | | | | | 25 | 15 |.........| 5 | 17 | something3 | something4 |
------------------------------------------------------------------------------------------------------------------
| 3 | 2 | 4 | 5 | 16 | 17 | 3 |.........| 1 | 15 | something5 | something6 |
So for every file from some selected list,witch means variable number of files, I need to read all the wordings and if a wording is connected to item in M_N_table and that item exist in selected files I have to write value of step and number to that files column as shown, if they don't exist it will be written blank value.
Problem I'm having is creating Table or DataList or GridView where I can have connection to item_id and wording_id when I'm editing data. I managed to create "pivot" datatable in C# in backcode, using all of these tables and created gridview with dynamic number of columns but problem is I don't have information about what item_id I'm actually editing it just goes back to changing value in datatable.
What is the best way to display this data? I tried making dynamic pivot table in SQL to display it directly with gridview but without aggregation it's impossible,so I had to do it with datatable's in C# back-code. And how can I make it so that when I edit data in displayed table I get the same changes in database?

GridView Column TextWrap like Excel in c# windows

I have a grid view containing column names a bit lengthy which are coming from database. So i want to make the wrapping like what we do in Excel in multiline rather than making the column fit to the length.
I used
dataGridView1.Columns["abcdefghijklmnop"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dataGridView1.Columns["abcdefghijklmnop"].DefaultCellStyle.WrapMode=DataGridViewTriState.True;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
When i do this i am able to fit the column length to the text length.but i want it to be in multiline.
Example : Should be like this
-------------------------------------------------
| abcde | klmno | uvwxy |
| fghij | pqrst | z |
-------------------------------------------------
Team1 | | | |
Team2 | | | |
TeamN | | | |
-------------------------------------------------
Now it is coming like this
-------------------------------------------------
| abcdefghij | klmnopqrst | uvwxyz |
| | | |
-------------------------------------------------
Team1 | | | |
Team2 | | | |
TeamN | | | |
-------------------------------------------------
these are the properties i am having
Pls help!!
You can do it many ways for example:
![dataGridView1.Columns\[0\].HeaderText = "VeryLong " + "LongLong" + Environment.NewLine + "LongLongLong";][1]
OR
dataGridView.ColumnHeadersHeightSizeMode =
DataGridViewColumnHeadersHeightSizeMode.AutoSize;
foreach (DataGridViewColumn column in dataGridView.Columns)
{
column.HeaderCell.Style.WrapMode= DataGridViewTriState.True;
}
Finally through edit datagridview columns manually:

Categories