PHPExcel insert new blank row after the last row in the sheet - phpexcel

How can I insert new blank row? ( for separating my rows ) .
My code is:
$num_rows = $xls->getActiveSheet()->getHighestRow();
//there need to insert a blank new row
$sheet->fromArray($header,null, "A".($num_rows + 1));
How can I solve this problem? Please, help me.

A blank row after the last row in the sheet? Why? Blank rows at the end of worksheet just take up memory.
But if you want to write data to cells beyond the end of the spreadsheet, then just do so....
$num_rows = $xls->getActiveSheet()->getHighestRow();
// Add 2 instead of 1
$sheet->fromArray($header,null, "A".($num_rows + 2));

Related

How to order table view with numbers 1-2-3

I have a table view , and I want to order my rows
for example first row take 1 , the second take 2
I have tried to use
protected static ObservableList<Employee> data = FXCollections.<Employee>observableArrayList();
int i = data.size() + 1;
in my column
But when I delete row ,
and add new row I got bug in order
for example : I have 2 rows , I have delete the first row,
and add new row it should take different order
but I got same number.
I hope you understand my language .
You can call myTableView.sort(); after you added or removed rows. Of course you have to define the sort order first, with a statement like this: myTableView.getSortOrder().add(myColumn);

VB.NET - Dynamically add in a table row, cells, and an image to each cell according to a directory?

I have been researching a way to dynamically add a table row, then a set of 3 cells, each containing an image which is pulled from a directory. So far I have found how to dynamically add a row and a cell which I have implemented and thus far I can get it to work, but not the way I had envisioned it. I think it is overwriting the existing table cell/ table row rather than adding a new one each time. Any help would be greatly appreciated or if there is a simpler way than what I have been trying that you may suggest.
Code is as follows:
'Populate image array
Dim FileArr As String() = Directory.GetFiles("C:\...File Location...\PortImages")
'Redim Trim Array
ReDim trimArr(FileArr.Length)
'Loop through to only get folder and file name from file array
For y As Integer = 0 To FileArr.Length - 1
TempName = FileArr(y)
trimArr(y) = "~" + TempName.ToString.Remove(0, 55)
Next
'Determine number of rows needed for 3 images across webpage
rowCount = FileArr.Length / 3
'loop through adding table rows as needed
For x As Integer = 1 To rowCount
ImageTable.Rows.Add(tRow)
'Set Row ID
tRow.ID = "tRow" + CStr(x)
'Set table row CSS class
tRow.CssClass = "ImageRow"
'Loop through each row adding a cell and 1 image
For z As Integer = 1 To 3
tRow.Cells.Add(tCell)
'Set cell ID
tCell.ID = "tCell" + CStr(arrCount)
'set css attribute
tCell.CssClass = "ImageCell"
'Add image to cell
tCell.Controls.Add(newImage)
'Set image CSS class
newImage.CssClass = "PortImages"
'set image to image name
newImage.ImageUrl = trimArr(arrCount)
'add one to count
arrCount += 1
Next
'add one to array count for next set of images
arrCount += 1
Next

Sorting a datatable by a column that contains part numbers and part letters

I have a datatable and I need to be able to sort either asc or desc by the jobcode column. Unfortunately the column field values contain both numbers and letters like this.
HD1233
HD12333
PG2839
TP9383
I need to extract the numbers, sort numerically and then put it back. So the above would look like this in the output.
HD1233
PG2839
TP9383
HD12333
I have a piece of code which does some sort of sort which is like this ...
Dim dtOut As DataTable = Nothing
dt.DefaultView.Sort = Convert.ToString("jobcode" & Convert.ToString(" ")) & drpAscorDesc.SelectedItem.Text
dtOut = dt.DefaultView.ToTable()
Im just unable to do it properly without the letters. Any advice would be greatly appreciated.
Add another column of type Integer to your DataTable.
Iterate through all DataRows, put values into new column based on job codes in these datarows (read value -> delete all non-numeric characters -> Int32.TryParse()).
Sort by new column.

Loop for each day in the current month and check rows for a match

How can I write a loop to run for each day in the current month and then check to see if the Dataset has a record that matches one of those days and take an action?
For Day As Integer = 1 To DaysInTheMonth
For Each row In MyRows
If row.Date.Day = Day Then
' Yup! Found Data for this day!
' Add Data to string
Else
' No Data To Display
' Add Blank Field String
End If
Next
Next
This generates too many rows in the table I have it building. Basically, every day gets as many rows as there are that contain data.
I'm building a HTML table that gets mapped into a chart using jquery so I need a for everyday of the month.
I think what would more suit your run would be having a day counter in the loop for the rows, so that you don't actually run over all the days again for each record in the datatable.
So now if you have the record its added to the string else skipped and the dat is incremented, so going down further you should get the required datapoints. give it a try
For Each row In MyRows
If row.Date.Day = Day Then
' Yup! Found Data for this day!
' Add Data to string
Else
' No Data To Display
' Add Blank Field String
End If
Day = Day + 1;
Next
You should drop the first For loop as that's causing all rows to be selected. Instead set Day = Today. Ie
Day as Integer = date.day

Adding new row to datatable's top

When we use datatable.newrow command, a new empty row added to bottom of rows. However I want newrow to added to top of datatable. How can I make it?
You use the NewRow to create a row with the same columns. To actually get it into the DataTable, you've got to do
myDataTable.Rows.InsertAt(myDataRow, 0);
Where 0 is the index you want to insert it at.
Here is the best example to add row in table
DataRow newRow = myDataTable.NewRow();
newRow[0] = "0";
newRow[1] = "Select one";
myDataTable.Rows.InsertAt(newRow, 0);
It's set the row on first
This One is Wrong
myDataTable.Rows.InsertAt(0,myDataRow);
Please use the below line instead of that
myDataTable.Rows.InsertAt(myDataRow,0);

Resources