How to add static information to dynamic data in Google Sheets? - sorting

I'm importing data into Google Sheets and then adding static information to it. I'd like my static data to be kept in alignment with a dynamic - is this possible? Is a script still required? Does anyone have an example?

it depends on your data structure, but there is a way with VLOOKUP formula
https://exceljet.net/excel-functions/excel-vlookup-function

Did you already find your solution to the problem? It sounds like you sort be able to sort the data with filters and still keep your note columns aligned.

this script could perhaps help:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getRange("A1:Z");
function onEdit(e) {
range.sort([{column: 2, ascending: false}]);
}
Sheet1 = name of the sheet
A1:Z = range to be sorted
column: 2 = column B
ascending: false = descending

Related

How can I write a script to auto sort a column with formulas and update every time a change is made?

I'm tracking the percentage of different stocks in column 3 and I want them to be automatically sorted by descending order every time the data is updated. The data in column 3 is formulaic. They are not text. How can I write this script?
Spreadsheet Here
tested on your sheet and works:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("TOP PICKS");
var range = sheet.getRange("A2:Z");
function onOpen(e) {
range.sort([{column: 3, ascending: true}]);
}

How do I send autosorted blank rows to the bottom?

I have a script that sorts Column B on edit, but there are two problems with it.
1 - It sends the rows with values to the bottom of the sheet.
2 - The numbers do not sort correctly. They should go in the order of 1,3,4,5,and 20, but when it sorts itself, it orders them as 1, 20, 3, 4, 5. It's like it only recognizes the 2 in 20 and places it after 1.
I've searched forum after forum trying to figure this out with no luck so help would be greatly appreciated.
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("050")
var range = sheet.getRange("A6:L200");
// Sorts by the values in column 2 (B)
range.sort({column: 2, ascending: true});
}
I don't know if this makes a difference or not, but the sheet that's being sorted uses VLOOKUP. Each Column from B on uses VLOOKUP.
=IFERROR(VLOOKUP(A6,data2019,3,FALSE),"")
First of all, there's no need to get the blank values in the first place, instead you can use getDataRange() to only get the range you need to sort.
Once you've got your range defined, you can sort it. Your values are not being sorted correctly (this is likely due to formatting of the cell from the VLOOKUP). You can simply set the format of the data range to number format using setNumberFormat('0') then sort the data to the order you're expecting.
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("050");
var range = sheet.getDataRange();
var numRows = range.getNumRows();
//sets the formatting of column B to a number in all populated rows
sheet.getRange(1, 2, numRows).setNumberFormat('0');
//sorts range by column B using newly formatted values
range.sort({column: 2, ascending: true});
}

alasql export to xlsx remove hashkey

I am using angularjs and javascript and want to export two arrays to Excel using alasql. The Excel file has two sheets, on every sheet there is one array.
In my Excel result I find an extra column $$hashkey.
According to the information I found, using angularjs, the $$hashkey is automatically removed. I also tried adding 'alasql.options.angularjs' but it did not help.
What am I doing wrong?
I am using the two arrays like this:
$scope.ExecutionsLC1: [[Execution,1,2,3],[Operators,1014,1019,1020],[Result,X,X,V]];
$scope.ExecutionsLC2: [[Execution,1,2,3],[Operators,2014,2019,2020],[Result,X,X,V]];
var opts = [{sheetid:'LC1',header:false},{sheetid:'LC2',header:false}];
var res = alasql('SELECT INTO XLSX("LCDetail.xlsx",?) FROM ?',[opts,[$scope.ExecutionsLC1,$scope.ExecutionsLC2]]);
it seems I can use angular.copy() to remove the $$hashkey.
var data1 = angular.copy($scope.ExecutionsLC1);
var data2 = angular.copy($scope.ExecutionsLC2);
var opts = [{sheetid:'One',header:false},{sheetid:'Two',header:false}];
var res = alasql('SELECT INTO XLSX("restest344b.xlsx",?) FROM ?',
[opts,[data1,data2]]);

epplus range merge AutoFilter

I'm trying to add the property
var range = sheet.Cells ["A6: R6"];
range.AutoFilter = true;
It does not work, apply the filter to all columns of the merge. How to solve? thanks
Remove the space in your cell range string. In other words:
var range = sheet.Cells ["A6: R6"];
Should be:
var range = sheet.Cells ["A6:R6"];
That will definitely trip it up. If that doesnt fix it post more of your code.

LinqToExcel - Need to start at a specific row

I'm using the LinqToExcel library. Working great so far, except that I need to start the query at a specific row. This is because the excel spreadsheet from the client uses some images and "header" information at the top of the excel file before the data actually starts.
The data itself will be simple to read and is fairly generic, I just need to know how to tell the ExcelQueryFactory to start at a specific row.
I am aware of the WorksheetRange<Company>("B3", "G10") option, but I don't want to specify an ending row, just where to start reading the file.
Using the latest v. of LinqToExcel with C#
I just tried this code and it seemed to work just fine:
var book = new LinqToExcel.ExcelQueryFactory(#"E:\Temporary\Book1.xlsx");
var query =
from row in book.WorksheetRange("A4", "B16384")
select new
{
Name = row["Name"].Cast<string>(),
Age = row["Age"].Cast<int>(),
};
I only got back the rows with data.
I suppose that you already solved this, but maybe for others - looks like you can use
var excel = new ExcelQueryFactory(path);
var allRows = excel.WorksheetNoHeader();
//start from 3rd row (zero-based indexing), length = allRows.Count() or computed range of rows you want
for (int i = 2; i < length; i++)
{
RowNoHeader row = allRows.ElementAtOrDefault(i);
//process the row - access columns as you want - also zero-based indexing
}
Not as simple as specifying some Range("B3", ...), but also the way.
Hope this helps at least somebody ;)
I had tried this, works fine for my scenario.
//get the sheets info
var faceWrksheet = excel.Worksheet(facemechSheetName);
// get the total rows count.
int _faceMechRows = faceWrksheet.Count();
// append with End Range.
var faceMechResult = excel.WorksheetRange<ExcelFaceMech>("A5", "AS" + _faceMechRows.ToString(), SheetName).
Where(i => i.WorkOrder != null).Select(x => x).ToList();
Have you tried WorksheetRange<Company>("B3", "G")
Unforunatly, at this moment and iteration in the LinqToExcel framework, there does not appear to be any way to do this.
To get around this we are requiring the client to have the data to be uploaded in it's own "sheet" within the excel document. The header row at the first row and the data under it. If they want any "meta data" they will need to include this in another sheet. Below is an example from the LinqToExcel documentation on how to query off a specific sheet.
var excel = new ExcelQueryFactory("excelFileName");
var oldCompanies = from c in repo.Worksheet<Company>("US Companies") //worksheet name = 'US Companies'
where c.LaunchDate < new DateTime(1900, 0, 0)
select c;

Resources