How to set Excel Import Preferences in InDesign CS6 using extendscript? - excel

This seems like it should be really simple, but for some reason I can't get it to work at all. The following code has no effect whatsoever:
function setExcelImportPrefs() {
with(app.excelImportPreferences){
rangeName = "A1:Z300";
sheetName = "whatever";
tableFormatting = TableFormattingOptions.excelFormattedTable;
}
}
And this doesn't work either:
function setExcelImportPrefs() {
with(app.excelImportPreferences){
app.excelImportPreferences.rangeName = "A1:Z300";
app.excelImportPreferences.sheetName = "whatever";
app.excelImportPreferences.tableFormatting = TableFormattingOptions.excelFormattedTable;
}
}
What am I doing wrong? I've Googled everything, and I'm at my wits end. (Note: I have InDesign CS6, version 8.0)
Edit: Put in a bracket that I accidentally left out when I was copying-and-pasting.

I'm not familiar with these settings, but you seem to have be missing a bracket. Just get rid of the with syntax all together and try
function setExcelImportPrefs() {
app.excelImportPreferences.rangeName = "A1:Z300";
app.excelImportPreferences.sheetName = "whatever";
app.excelImportPreferences.tableFormatting = TableFormattingOptions.excelFormattedTable;
}

Related

AndroidStudio - Flutter code alignment gets worse

AndroidStudio's Flutter code alignment gets worse when using Riverpod and some others. Because of this, code is unreadable and hard to understand at first sight.
I don't know if this is a major issue, but I can't find a solution for it on the Internet.
Are there any hacks or tips?
See the examples
This is what I expect...
`
if (ref.read(selectedDistributorProvider.notifier).state != null) {
SharedPreferences pref = await SharedPreferences.getInstance();
String stme = DateFormat('yyyy-MM-dd HH:mm').format(DateTime.now()).toString();
pref.setString('pref_shopInST', stme);
pref.setString('pref_selected_dealer', ref.read(selectedDistributorProvider.notifier).state!.drid ?? "");
ref.read(dealerSelectedStatusProvider.notifier).state =
!(ref.read(dealerSelectedStatusProvider.notifier).state);
} else {
AppClass().showSnackBar('Please select dealer', context);
}
`
The Image is what Ctrl + Alt + L gives...
https://ibb.co/k5tS5jb

Excel Cell Formatting - Horizontal alignment

I am trying to apply 'Fill' horizontal formatting to a cell but it is not working. I am using predefined Excel.HorizontalAlignment namespace to do so.
Host: Office 365, Excel
Code:
Excel.run(ctx => {
const cell = ctx.workbook.getSelectedRange().getCell(0, 0);
cell.format.fill.color = "FFFF00";
cell.format.horizontalAlignment = Excel.HorizontalAlignment.fill;
cell.format.font.size = 1;
return ctx.sync();
});
It throws with:
Unhandled promise rejection InvalidArgument: The argument is invalid or missing or has an incorrect format.
However, when I use the same code and set the alignment to 'Center' as such:
Excel.run(ctx => {
const cell = ctx.workbook.getSelectedRange().getCell(0, 0);
cell.format.fill.color = "FFFF00";
cell.format.horizontalAlignment = Excel.HorizontalAlignment.center;
cell.format.font.size = 1;
return ctx.sync();
});
Everything works just fine. What am I doing wrong?
Edit: documentation for reference: https://learn.microsoft.com/pl-pl/javascript/api/excel/excel.rangeformat?view=office-js#horizontalalignment
We reproed this locally, this should be a bug, we will fix it.
I withdraw this suggestion
cell.format.horizontalAlignment = xlFill;
or
cell.format.horizontalAlignment = Excel.HorizontalAlignment.xlFill;
I found this at horizontalAlignment doesn't work with xlFill

disable/hide UISearchBar when datasource is nil

I want to make sure that no search bar is displayed when the datasource of my table view is empty. (Makes sense, no? shouldn't that be default behaviour?)
Here's a piece of my code that tries (currently uncommented) different things to accomplish that, but somehow it doesn't work.
Can anybody advise me what I'm doing wrong? Let me know if you need more snippets.
messagesArray=loadMessages()
DispatchQueue.main.async {
if (self.messagesArray.count==0){
self.noMessageview.isHidden=false
//self.searchController.searchBar.isHidden = true
//self.searchController.isActive = false
} else{
self.noMessageview.isHidden=true
//self.searchController.searchBar.isHidden = false
//self.searchController.isActive = true
}
self.spinner.stopAnimating()
self.refreshControl.endRefreshing()
self.tableView.reloadData()
}
UPDATE:
I declare the search controller like this:
let searchController = UISearchController(searchResultsController: nil)
and in the ViewDidLoad I do:
navigationItem.searchController = searchController
I believe you are using iOS 11 because of setting UISearchController from navigationItem, Thus you can use the following code to remove it:
if #available(iOS 11.0, *) {
self.navigationItem.largeTitleDisplayMode = .never;
self.navigationItem.searchController = nil
} else {
// Fallback on earlier versions
self.navigationItem.titleView = nil
};
I had some problem and i think its iOS 11 bug, when removing the UISearchController, the view doesn't get adjusted thus i had to call this right before removing UISearchController.
self.navigationItem.largeTitleDisplayMode = .never;
Thats all.

Office JS issue with recognising ListItems

I'm trying to add a paragraph at the end of the document and escape the possibility of the newly added paragraph to be added inside a list (if the document is ending with a list).
I have the following code:
let paragraph = paragraphs.items[paragraphs.items.length - 1]
let p = paragraph.insertParagraph('', window.Word.InsertLocation.after)
if (paragraph.listItemOrNullObject) {
p.detachFromList()
p.leftIndent = 0
}
The following happens: if there is a ListItem, the code works. If not, it breaks inside the if condition, like I wrote paragraph.listItem.
Shouldn't this be used like this?
EDIT - error thrown:
name:"OfficeExtension.Error"
code:"GeneralException"
message:"GeneralException"
traceMessages:[] 0 items
innerError:null
▶debugInfo:{} 4 keys
code:"GeneralException"
message:"GeneralException"
toString:function (){return JSON.stringify(this)}
errorLocation:"Paragraph.detachFromList"
the issue here is that the *.isNullObject methods/properties does not return a regular js 'null' object, but a NullObject (a special framework type of null).
check out this code i rewrote it i think in a more efficient way. excuse my js, you can port it to ts.
hope this helps.
Word.run(function (context) {
var listI = context.document.body.paragraphs.getLast().listItemOrNullObject;
context.load(listI);
return context.sync()
.then(function () {
if (listI.isNullObject) { // check out how i am validating if its null.
console.log("there is no list at the end")
}
else {
context.document.body.paragraphs.getLast().detachFromList();
context.document.body.paragraphs.getLast().leftIndent = 0;
return context.sync();
}
})
})
listItemOrNullObject will return a null object if it isn't a ListItem. Conceptually you're if is asking "if this is a list item or it isn't a list item" which effectively will also return true.
It is failing here you are attempting to detach from a non-existent list. I would take a look at isListItem. This will tell you specifically if the paragraph is a ListItem so you only execute p.detachFromList() when in fact it is part of a list.

PHP-like string parsing

I'm writing a mini-console of sorts and I'm trying to figure out how to extract things from a link. For example, in PHP this is a request variable
so:
http://somelink.com/somephp.php?variable1=10&variable2=20
Then PHP figures out the url parameters and assigns them to a variable.
How would I parse something like this in Swift?
So, given the string I'd want to take: variable1=10 and variable2=20 etc, is there a simple way to do this? I tried googling around but didn't really know what I was searching for.
I have a really horrible hacky way of doing this but it's not really extendable.
You’d be wanting NSURLComponents:
import Foundation
let urlStr = "http://somelink.com/somephp.php?variable1=10&variable2=20"
let components = NSURLComponents(string: urlStr)
components?.queryItems?.first?.name // Optional("variable1")
components?.queryItems?.first?.value // Optional("10")
You might find it helpful to add a subscript operator for the query items:
extension NSURLComponents {
subscript(queryItemName: String) -> String? {
// of course, if you do this a lot,
// cache it in a dictionary instead
for item in self.queryItems ?? [] {
if item.name == queryItemName {
return item.value
}
}
return nil
}
}
if let components = NSURLComponents(string: urlStr) {
components["variable1"] ?? "No value"
}

Resources