i couldn't ask my question very well. I put here a table that i want to create in google sheet, excel or other. Anyone can help me please?
street name
number
Impasse Malabane
9
Impasse Malabane
Impasse du Puech
Impasse Bimet
Rue Levers
Impasse du Puech
1 bis
9
1 bis
6
26
Rue Levers
26
5
2 bis
2
28
Impasse Bimet
6
8
1
Impasse Bimet
2
8 bis
Impasse Malabane
5
Impasse du Puech
2 bis
Impasse Malabane
8
Impasse Malabane
8 bis
Impasse du Puech
1
Rue Levers
28
In Google Sheets, assuming that your original headers "Street Name" and "Number" are in A1 and B1 (with the data in A2:B), place this in D2:
=ArrayFormula(TRANSPOSE(TRIM({UNIQUE(FILTER(A2:A,A2:A<>"")),TO_TEXT(SPLIT(TRANSPOSE(TRIM(SPLIT(TEXTJOIN("| ",1,{IFERROR(SUBSTITUTE(VLOOKUP(UNIQUE(FILTER(A2:A,A2:A<>""))&TRANSPOSE(UNIQUE(FILTER(B2:B,B2:B<>""))),A2:A&B2:B,1,FALSE),UNIQUE(FILTER(A2:A,A2:A<>"")),"")),SEQUENCE(COUNTA(UNIQUE(FILTER(A2:A,A2:A<>""))),1,1,0)})&"|","| 1|",0,1))),"|"))})))
This one formula will generate all results. As you add new data in A2:B, it will be added without any need to edit the formula.
This should work in Google Apps Script:
function myFunction() {
// initialize
var ss = SpreadsheetApp.getActiveSheet();
var lr = ss.getLastRow();
var values = ss.getRange(2,1,lr-1,2).getValues();
console.log(values.sort());
var result = [];
console.log(result);
var prevCol = '';
// populate array
for (i = 0; i < values.length; i++) {
if (values[i][0] != prevCol) {
result.push([values[i][0], values[i][1]]);
}
else {
result[result.length-1].push(values[i][1]);
}
prevCol = values[i][0];
}
console.log(result);
// transpose array
var newArray = [];
for(var i = 0; i < result.length; i++){
newArray.push([]);
};
for(var i = 0; i < result.length; i++){
for(var j = 0; j < result.length; j++){
newArray[j].push(result[i][j]);
};
};
// write to range
var dest = ss.getRange(2,4,newArray[0].length,newArray.length);
dest.setValues(newArray);
}
It's a little difficult to understand the question, but I think you are trying to convert a 2-column table into a multi-column table with data.
You can do this with an array formula. First, copy all your distinct street names into a single row. In the picture below, this was done in cells F1:I1.
Cell F2 formula:
{=IFERROR(INDEX($B$2:$B$9999, SMALL(IF($F$1=$A$2:$A$9999, ROW($A$2:$A$9999)-ROW($A$2)+1), ROW(1:1))),"")}
You need to press CTRL+SHIFT+ENTER to get those curly brackets to make this an array formula. Drag it down as far as you need, well beyond as many rows as you would expect. It's wrapped in an IFERROR handler to show a blank if no more results are found.
The formulas for the other columns are similar. You just need to change the reference from $F$1 to $G$1 and so on, and also repeat the array trick.
Also, if you have more than 9999 rows, just adjust the end row number in the formula.
This VBA script does it. Assuming your data starts in A1 in Sheet1.
Sub transform()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1")
Dim first_col As String: first_col = "A"
Dim ws2 As Worksheet
Dim c_last As Range
Dim c As Range
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
Dim key As Variant
Dim arr() As String
Set c_last = ws.Cells(ws.Rows.Count, first_col).End(xlUp)
For Each c In ws.Range(first_col & 2, c_last)
If dict.Exists(Trim(c)) Then
dict.Item(Trim(c)) = dict.Item(Trim(c)) & "$" & CStr(c.Offset(, 1))
Else
dict.Item(Trim(c)) = CStr(c.Offset(, 1))
End If
Next
Set ws2 = ws.Parent.Sheets.Add(After:=ws.Parent.Worksheets(ws.Parent.Worksheets.Count))
Set c = ws2.Range("A1")
For Each key In dict.Keys()
c = key
arr = Split(dict.Item(key), "$")
c.Offset(1).Resize(UBound(arr) + 1) = Application.Transpose(arr)
Set c = c.Offset(, 1)
Next
End Sub
Before:
After:
A correction of Carlos' proposal (Google Sheets) :
function myFunction() {
// initialize
var ss = SpreadsheetApp.getActiveSheet();
var lr = ss.getLastRow();
var values = ss.getRange(2,1,lr-1,2).getValues();
values.sort();
var result = [];
var prevCol = '';
// populate array
for (i = 0; i < values.length; i++) {
if (values[i][0] != prevCol) {
result.push([values[i][0], values[i][1]]);
}
else {
result[result.length-1].push(values[i][1]);
}
prevCol = values[i][0];
}
// determine maximum length
var max = 0 ;
for(var i = 0; i < result.length; i++){
max=Math.max(max,result[i].length);
};
// complete the array by replacing null values with an empty string
for (var i = 0; i < result.length; i ++) {
for (var j = 0; j < max; j ++) {
if (result[i][j] == null) {result[i][j] = "";}
}
}
// transpose array
var result = transpose(result);
// write to range
ss.getRange(2,4,result.length,result[0].length).setValues(result);
}
function transpose(a){
return Object.keys(a[0]).map(function (c) { return a.map(function (r) { return r[c]; }); });
}
I have two text columns which look like this:
and now I need to make a bubble chart that looks like this:
Any idea how I can achieve this using excel 2016?
There is a way to do this by using Javascript. This langage has a lot of powerful libraries for data visualization and data processing. And there is a way to use it in Excel by using an Excel Add-in called funfun.
I have written a working code for you:
https://www.funfun.io/1/#/edit/5a7c4d5db8b2864030f9de15
I used an online editor with an embedded spreadsheet to build this chart. I use a Json file(short/full underneath Settings) to get the data from the spreadsheet to my javascript code:
{
"data": "=A1:B18"
}
I then store it in local variables in the script.js so I can use them correctly in the chart I will create:
var Approaches = []; // list of Approaches
var Contribution = []; // list of contribution
var tmpC = [];
/*
* Parse your spreadsheet to count how much approaches and contribution there are
*/
for (var x = 1; x < $internal.data.length; x++) {
if (Approaches.indexOf($internal.data[x][0]) <= -1)
Approaches.push($internal.data[x][0]);
if (tmpC.indexOf($internal.data[x][1]) <= -1)
tmpC.push($internal.data[x][1]);
}
/*
* sort the array so that other is at the end
* (remove if you want you don't care about the order, replace 'tmpC' by 'Contribution' above)
*/
for (var t = tmpC.length - 1; t >= 0; t--)
Contribution.push(tmpC[t]);
var techniquesIndex = new Array(Contribution.length); // how much of one contribution is made per approach
var total = 0; // total of contribution
var totalPerApproaches = new Array(Approaches.length); //total of contributions for one Approach
for (var z = 0; z < totalPerApproaches.length; z++) {
totalPerApproaches[z] = 0;
}
var data = []; // data for the chart
/*
* Parse your every approach
*/
for (var x = 0; x < Approaches.length; x++) {
for (var z = 0; z < techniquesIndex.length; z++) {
techniquesIndex[z] = 0;
}
/*
* Parse your spreadsheet to count the number of contribution in this approach
*/
for (var y = 0; y < $internal.data.length; y++) {
if (Approaches.indexOf($internal.data[y][0]) == x) {
total += 1;
techniquesIndex[Contribution.indexOf($internal.data[y][1])] += 1;
}
}
for (var c = 0; c < Contribution.length; c++) {
/*
* calculate the total of contribution on this approach
*/
totalPerApproaches[x] += techniquesIndex[c];
/*
* removes the values equals to zero off the chart
* (remove this condition if you want to show the zeros)
*/
if (techniquesIndex[c] == 0)
continue;
/*
* adds a bubble to the charts with the number of Contribution per Approach
*/
data.push(
{
x: x, // -> index of array Approach[x]
y: c, // -> index of array Contribution[c]
z: techniquesIndex[c], // number of contribution[c] in Approach[x]
name: techniquesIndex[c] // ..
});
}
}
The $Internal.data is the data from the spreadsheet accessible thanks to the Json file. The array data (at the end) will be used to create all the bubbles of the charts.
Once I have my data stored in the right format I create the chart in index.html using a data visualization library called Highcharts, it has lots of examples and good documentation for beginners. You can choose to add many options for your chart and at the end you pass your data to the chart as such:
series: [{
data: data // use the data from script.js
}]
Once you've build your chart you can open it in Excel by pasting the URL in the Funfun excel add-in. Here is how it looks like with my example:
You can as much lines as you want you just need to make sure that the range of data in the Json file is what you need.
you can then save the chart in many formats:
Hope this helps !
Disclosure : I’m a developer of funfun
I am using Visual Studio 2010 and want to count number of lines in a C# textbox. I have tried Textbox.Lines.Count but it is not working as "Lines" is no more available in 2010.Is there any alternate way?
Try use
var count = Textbox.Lines.Length;
More detail here
Or try this:
string[] tmpArray = textBox1.Lines;
int count = tmpArray.Length;
int first = 0;
int last = 0;
count=0;`enter code here`
last = textBox.GetLastVisibleLineIndex();
count++;
while (first <= last)
{
String dummy = textBox.GetLineText(first);
if (dummy.Contains("\n") || dummy.Contains("\r") || dummy.Contains("\r\n"))
{
dummy = dummy.TrimEnd('\r', '\n');
count++;
}
first++;
}
I am usind pdfbox and trying to colour the header of the table; I had done the table drawing correctly using tutorial ' http://fahdshariff.blogspot.in/2010/10/creating-tables-with-pdfbox.html'
The code as follows
//draw the rows
float nexty = y ;
for (int i = 0; i <= rows; i++) {
contentStream.drawLine(margin, nexty, margin+tableWidth, nexty);
nexty-= rowHeight;
}
//draw the columns
float nextx = margin;
for (int i = 0; i <= cols; i++) {
contentStream.drawLine(nextx, y, nextx, y-tableHeight);
nextx += (colWidths != null) ? colWidths[i] : colWidth;
}
I got the code for colouring as follows:
contentStream.setNonStrokingColor( Color.RED );
contentStream.fillRect( 10, 10, 100, 100 );
I tried to put it but its not working as needed. I need to colour table header only. How can I achieve that. Please help me.
I have a program in j2me that get strings and data from an wml/asp page.
Using this code:
HttpConnection con = (HttpConnection) Connector.open(
"http://localhost:"+port+"/MobileWebWIthConnection/ShowCourseinsemester.aspx?StudentId="+ID+"&Year="+Year+"&Semester="+Semester);
DataInputStream in = new DataInputStrea(con.openInputStream());
int len = (int) con.getLength();
byte[] info = new byte[len];
in.readFully(info);
result = new String(info);
switchDisplayable(null, getStudentCourses());
stringItem2.setText(result);
When my j2me application try to read and store the data from this page:
"http://localhost:"+port+"/MobileWebWIthConnection/ShowCourseinsemester.aspx?StudentId="+ID+"&Year="+Year+"&Semester="+Semester
the text which is placed in the string called (result) is nothing similar to expected figure below:
It's taking the content without formatting as below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<wml>
<card>
<p><b>Student Name :</b> Arin Rizk </p>
<p><b>Student ID</b> : 20111</p>
<p>first Semester ,2011</p>
1 - Course Name : DDD | Credits Number : 3 | Mark : 70 </br> 2 - Course Name : EEE | Credits Number : 3 | Mark : 65 </br> 3 - Course Name : EEE | Credits Number : 3 | Mark : 65 </br> 4 - Course Name : EEE | Credits Number : 3 | Mark : 90 </br>
</card>
</wml>
so when I assigned this text to the StringItem it's showing as below in the fig.
stringItem2.setText(result);
How can get my j2me to view the strings as the original formatted page?
I solved it , it was a little bit tricky specially that in j2me there is no (split method) .
so simply I created one.
I decleared it
String[] split (String x){
int num=0;
for(int i=0; i<x.length(); i++) // count the number of ','
if(x.charAt(i)==',')
num++;
String[] r=new String[num];
for(int i=0; i<num; i++)
{
int loc=x.indexOf(","); //loc is the location of each ','
r[i]=x.substring(0,loc);
x=x.substring(loc+1);
}
return r;
}
and then I applied it and display the results in a list
HttpConnection con = (HttpConnection) Connector.open("http://localhost:"+port+"/MobileWebWIthConnection/ShowCourseinsemester.aspx?StudentId="+ID+"&Year="+Year+"&Semester="+Semester);
DataInputStream in = new DataInputStream(con.openInputStream());
int len = (int) con.getLength();
byte[] info = new byte[len];
in.read(info);
result = new String(info);
String[] a=split(result);
getList().deleteAll();
for(int i=1; i<a.length; i++)
getList().append(a[i], null);
switchDisplayable(null,getList());
and the results were as wanted ( in rows ) without the full source code from the wml page.