Google Sheets' clearContent() not consistent? - google-sheets-api

It's my first day using googlescript and I'm having a little trouble with the clearContent() method. The data I am testing is one row normal, then bold, then normal again. Like so:
First row.
Second row.
Third row.
When I run my code, it's clearing out the first row just how I want, then skips past the second row since it's bold. However the third row is getting skipped too. Any suggestions? (Or am I just missing something silly?)
for (var row=1; row<=numRows; row++) {
for (var column=1; column<=numCols; column++){
//For debugging
Browser.msgBox("(" + row + "," + column + ")|" + range.getCell(row, column).getValue() + "|" + range.getCell(row, column).getFontWeight() + "|", Browser.Buttons.OK_CANCEL);
if (values[row][column] != "" && range.getCell(row, column).getFontWeight() == "normal") {
range.getCell(row, column).clearContent();
}
}
}

After messing with the code a bit and assigning some variables this worked. Not exactly sure why.
for (var row=1; row<=numRows; row++) {
for (var column=1; column<=numCols; column++){
value = range.getCell(row, column).getValue();
fontWeight = range.getCell(row, column).getFontWeight();
//For debugging
//Browser.msgBox("(" + row + "," + column + ")|" + range.getCell(row, column).getValue() + "|" + range.getCell(row, column).getFontWeight() + "|", Browser.Buttons.OK_CANCEL);
if (value != "" && fontWeight == "normal") {
range.getCell(row, column).clearContent();
}else if (fontWeight == "bold") {
break;
}
}
}

Related

Check the null or empty record condition

I wanted to know if I did this code well, to check if the coding of a record is null or empty, getTraduction (), if I did something wrong, just let me know where I went wrong.
because I would like to have even null records printed
public void getTraduttoreIt_CLASS_HDR_NLS() throws Exception {
List<ClassHdrNls> db2 = getListCLASS_HDR_NLS();
List<DizioPt> sqlServer = getListDizioPt();
BufferedWriter scrivi = new BufferedWriter(
new FileWriter("C:/Users/francesco/Desktop/Table_ClassHdrNls_Sez3.txt"));
for (int i = 0; i < db2.size(); i++) {
for (int j = 0; j < sqlServer.size(); j++) {
if (db2.get(i).getNlsClassName().equals(sqlServer.get(j).getKeyword())) {
System.out.println("-------------------FILE N°3---------------------------");
System.out.println("-------------------ITALIANO---------------------------");
System.out.println("CLASS_NAME: " + db2.get(i).getClassName());
scrivi.newLine();
scrivi.write("CLASS_NAME: ");
scrivi.write(db2.get(i).getClassName());
scrivi.newLine();
System.out.println("NLS_CLASS_NAME: " + db2.get(i).getNlsClassName());
scrivi.write("NLS_CLASS_NAME: ");
scrivi.write(db2.get(i).getNlsClassName());
scrivi.newLine();
System.out.println("NLS_PL_CLASS_NAME: " + db2.get(i).getNlsPlClassName());
scrivi.write("NLS_PL_CLASS_NAME: ");
scrivi.write(db2.get(i).getNlsPlClassName());
scrivi.newLine();
System.out.println("KEYWORD: " + sqlServer.get(j).getKeyword());
scrivi.write("KEYWORD: ");
scrivi.write(sqlServer.get(j).getKeyword());
scrivi.newLine();
System.out.println("LINGUA ITALIANO: " + db2.get(i).getLanguage() + " ***");
scrivi.write("LINGUA ITALIANO: ");
scrivi.write(db2.get(i).getLanguage() + " ***");
scrivi.newLine();
// Faccio un controllo se il valore è diverso da null o il record è vuoto
if (sqlServer.get(j).getTraduzione() == null || sqlServer.get(j).getTraduzione().isEmpty()) {
System.out.println("TRADUZIONE: ***********");
scrivi.write("TRADUZIONE: ");
scrivi.write("*******************");
scrivi.newLine();
} else {
System.out.println("TRADUZIONE: " + sqlServer.get(j).getTraduzione());
scrivi.write("TRADUZIONE: ");
scrivi.write(sqlServer.get(j).getTraduzione());
scrivi.newLine();
}
System.out.println("-------------------------------------------------------");
scrivi.flush();
}
}
}
scrivi.close();
}
Output:
Print only non-null and non-empty records.
I also want to print null records
this line:
if (db2.get(i).getNlsClassName().equals(sqlServer.get(j).getKeyword()))
could be why you are not printing null values, since it forces printing only after there is a match.
You should inspect your data (print all of it) to see what you are getting.
If you are finding null values, then that means printing inside the if condition is what's stopping you from seeing the null values get printed.

Accessing Photoshop preferences

I'm trying to loop over the Photoshop preferences. This should be as straightforwards as
for (i = 0; i < app.preferences.length; i++)
{
alert(app.preferences[i]);
}
only the object app.preferences doesn't have a length and accessing each item such as
alert(app.preferences.beepWhenDone); //bool
works, but is tedious and is also possibly version dependent. I know most of them are read-only, but I'm quite keen to list them all.
This should do what you want:
alert(app.preferences.reflect.properties.sort().join("\r"));
Or actually, to also let you inspect the actual values, you could do something like this:
var prefsObject = app.preferences;
var prefs = app.preferences.reflect.properties.sort();
var prefString = "Photoshop Preferences\r";
for(var i = 0; i < prefs.length; i++) {
try {
prefString += prefs[i] + ": " + prefsObject[prefs[i]] + "\r";
} catch (e) {
prefString += prefs[i] + ": " + e.message + "\r";
}
}
alert(prefString);

How can i Solve this Code of creating ISO-8385 parser in Java?

Bellow is my code.
for (int i : Utility.getFieldPosList(hexBitmap)) {
IsoValue mtl = this.parserConfig.get(i);
if (mtl == null) {
break;
}
field = parseField(mtl, isoMessageFields);
mtl.setValue(field);
responseMessage.setField(i, mtl);
if(mtl.getIsoType() == IsoType.LLVAR){
isoMessageFields = isoMessageFields.substring(field.length() + 2);
}else if(mtl.getIsoType() == IsoType.LLLVAR){
isoMessageFields = isoMessageFields.substring(field.length() + 3);
}else{
isoMessageFields = isoMessageFields.substring(field.length());
}
sb.append("\nin[ " + i + " ]<" + field + ">");
}
I am not getting the exact value of i, so in this circumstances, I need some suggestion .

Visual SourceSafe script starting out

I have never wrote a script before and I was asked today to make a Visual SourceSafe script that returns all of the labels that are stored.
I have 0 idea on how to start this as I have never wrote a script before. Can anybody point me in the right direction with this please?
Thanks!
You can use the History command of SourceSafe to get the history info of an item and extract the label info you need.
Here is a simple sample for you:
private void GetItem(VSSItem vssItem)
{
if (vssItem.Type == 0) //Type == 0 means it's a project
{
bool bIncludeDeleted = false;
IVSSItems vssItems = vssItem.get_Items(bIncludeDeleted);
foreach (VSSItem vssitem in vssItems)
{
GetItem(vssitem);
foreach (IVSSVersion vssVersion in vssitem.get_Versions(0))
{
string vssItemName = "";
if (vssVersion.VSSItem.Name == "")
vssItemName = vssitem.Spec;
else
vssItemName = vssVersion.VSSItem.Spec;
if (vssVersion.Action.IndexOf("Label") > -1 )
{
if (vssitem.Spec == vssVersion.VSSItem.Spec)
{
MessageBox.Show("Item " + vssItemName + " in " + "Version " + vssVersion.VersionNumber.ToString() + " With the lable: " + vssVersion.Label);
}
}
}
}
}

i want to loop through all items in the dataGrid and compare with a particular one

I want to loop through all the items in the datagrid and compare them with a particular item(unique) present in the datagrid itself, and if it is not equal that unique item ("My Pipeline" is the name of that particular item) with which i want to compare rest of the items with then delete that item and move on to the next item and compare again.
intRowCount = Browser("Browser").appliaction("abc").FlexTitleWindow("Views").AdvancedDataGrid(dgView).GetItemsCount
For i=0 to intRowCount
Browser("Browser").appliaction("abc").FlexTitleWindow("Views").AdvancedDataGrid(dgView).SelectIndex i
If Browser("Browser").appliaction("abc").FlexTitleWindow("Views").AdvancedDataGrid(dgView).GetROProperty("SelectedItem") <> Browser("Browser").appliaction("abc").FlexTitleWindow("Views").AdvancedDataGrid(dgView).GetROProperty("My Pipeline") Then
Browser("Browser").appliaction("abc").FlexTitleWindow("Views").FlexButton("Delete View").Click
I want to loop through until all other views are deleted except my Default view (MY Pipeline).
Please suggest some logic.
This is the code that i have implemented to download the data from DataGrid to CSV file.
This may be useful to you.
Remember dgSessionReport is my Datagrid, first_name and last_name is my datafield name.
First I am creating a String that contains csv data and then i am writing that into file having extension .csv
You need to do is in the 2nd for loop you need to write
if(searchString == dataProvider[i].first_name)
{
dataProvider[i].first_name = "";
}
Here is my code
public function btnDownload_click():void
{
var csvData:String = "";
var columns:Array = dgSessionReport.columns;
var dataProvider:Object = dgSessionReport.dataProvider;
for(var i:int=0;i<columns.length;i++)
{
if(i != columns.length - 1)
{
csvData += columns[i].headerText + ",";
}
else
{
csvData += columns[i].headerText;
}
}
csvData += "\n";
for(var i:int=0;i<dataProvider.length;i++)
{
csvData += dataProvider[i].first_name + ",";
csvData += dataProvider[i].last_name;
csvData += "\n";
}
var fileRef:FileReference = new FileReference();
fileRef.save(csvData,"Session Report.csv");
}