JavaScript for Automation (JXA) Excel open workbook question - javascript-automation

How do you open an Excel workbook using JavaScript for Automation?
let excelApp = Application("Microsoft Excel");
let path = Path("/Users/me/Test.xlsx");
excelApp.openWorkbook(path);
gets error 50 "parameter error".

I figured it out:
let excelApp = Application("Microsoft Excel");
let testWorkbook = excelApp.openWorkbook({workbookFileName: "/Users/me/Test.xlsx"});
I also figured out how to get the contents of the data:
let varr = testWorkbook.sheets["firstsheet"].usedRange.value();
source: Yosemite JXA release notes and Script Editor dictionary entry for Microsoft Excel

Related

Exception: Service unavailable: Documents Error in Google Doc Apps Script

I have an odd issue with a Google Doc Apps Script. It's been working for months without any issues. Then yesterday I get the Error Message: "Exception: Service unavailable: Documents" whenever I try to position an image blob (either from a URL Fetch or from getFileById). I simplified my code to this, and no matter what image I use, I always get the error.
function debugProc () {
var rLlogoborderlessId = '1ZhOX_aneaAhM0XJV4oQHGfNPUzaVETgu';
doc = DocumentApp.getActiveDocument();
curBody = doc.getBody();
var addlines = curBody.appendParagraph('');
var imgpara = curBody.appendParagraph("");
imgpara.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
var logoimage = DriveApp.getFileById(rLlogoborderlessId).getBlob();
var addlineslogo = curBody.appendParagraph('');
var k2nplogo = addlineslogo.addPositionedImage(logoimage);
// Error: Exception: Service unavailable: Documents
}
I tried multiple different computers and browsers. Nothing works. No workaround that I can find. How can I resolve this?
By reading your new comments I understand that the case isn't reproducible on new documents. The issue may have originated from a problem with your project or a bad configuration. To fix it, you only need to create a new Doc and copy all the data there. Feel free to leave a comment below if you need help with the migration.

Apps Script (Error Exception: The document is inaccessible. Please try again later. Creator # Code.gs:10)

I wrote a script to automatically create and fill in the required fields in the file, but an error
Error Exception: The document is inaccessible. Please try again later. Creator # Код.gs:10
Please look at the code, tell me where I was wrong.
function Creator() {
const docFile = DriveApp.getFileById("1DhHBAd3ssYMgbbxJatK6_URxBPdoPk2K");
const tempFolder = DriveApp.getFolderById("16keE-_Dm0gglO42Lw0IphiPHYK-_TFXH");
const pdfFolder = DriveApp.getFolderById("1ZsmW9UPNaqgjt8kFh3y9h8tdBLAtj7gC");
const tempFile = docFile.makeCopy(tempFolder);
const tempDocFile = DocumentApp.openById(tempFile.getId());
const body = tempDocFile.getBody();
var list = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var l=list.getLastRow();
for (var i=2; i <= l; i++) {
var a1 = list.getRange(i, 3).getValue();
var a2 = list.getRange(i, 4).getValue();
body.replaceText("{ПІБ}", a1);
body.replaceText("{Назва структури}", a2);
tempDocFile.saveAndClose();
const pdfFile = tempDocFile.getAs(MimeType.PDF);
pdfFolder.createFile(pdfFile).setName(a1);
tempFolder.removeFile(tempFile);
}
}
Assuming that the code line having the error is
var l=list.getLastRow();
It's very likely that you faced a Google environment glitch (I have faced the same error this weekend). In situations like this there is nothing else to do than to wait a bit and try again.
If you are developing a script / add-on / web-app to be used by others or you would like to handle this automatically you could use an algorithm like exponential backoff
If the error occurred on the previous code lines calling the Document Service, the problem might be caused for trying to open non Google Document file i.e. Microsoft Word file (.docx). In this case you should first convert the file to Google Document format and use the converted document instead of the original.
Related
Error message: "Cannot connect to Gmail" (Google services having glitches)
Google Script Document Inaccessible Error - creating and attempting to open document in code
Exception: The document is inaccessible. Please try again later. Google Scripts
Resources
Scripts implementing the exponential backoff algorithm in Google Apps Script
https://gist.github.com/peterherrmann/2700284
https://github.com/RomainVialard/ErrorHandler

Can you import Stock Options data into Google Sheets

I'm trying to create Stock Options watchlist in Google sheet but its not working. Let's say I need to pull AMZN Jun 4000 Option (AMZN220617C04000000) Bid price in to google sheet but I get an error "resource at url not found"
=TRANSPOSE(IMPORTXML(CONCATENATE("https://finance.yahoo.com/quote",AMZN220617C04000000,"?p=",AMZN220617C04000000,""""),"//tr[bid]"))
Is there an option to make this work ? Or can this be possible in MS Excel running on Mac?
Thank you for your time and Support
You cannot fetch data with importxml in this case because the webpage is built by javascript on your side and not on the server side. Nevertheless, all the data is available in a json which you can get this way
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
var data = JSON.parse(jsonString)
you can then get informations you need from 'data'
https://docs.google.com/spreadsheets/d/1sTA71PhpxI_QdGKXVAtb0Rc3cmvPLgzvXKXXTmiec7k/copy

Google DriveService API Upload with mimetype application/vnd.google-apps.document failing

I am trying to upload a file to Google Drive and share/access the same via Google Docs. I have copied below the code snippet. I am using Google Drive API V3. It's failing with error GoogleApiException:
Google.Apis.Requests.RequestError Bad Request [400].
Not sure what's missing in the request. I have tried few additional parameters of File, but it always returns Bad Request Error. If anyone know the solution please let me know.
string fileType = "application/vnd.google-apps.document";
var newFile = new File
{
Name = title,
MimeType = fileType,
Description= title,
};
var uploadProgress = DriveService.Files.Create(newFile, fileStream, fileType);
Google.Apis.Upload.IUploadProgress progress = uploadProgress.Upload();
I believe that in v3 you do not need to specify the mimeType as a third parameter for DriveService.Files.Create()
This is opposed to Files.Insert() in v2, where you would also need to specify Convert = true
Change to:
var uploadProgress = DriveService.Files.Create(newFile, fileStream);
Make sure that your original mimeType is compatible with Google Docs
Make sure that you build fileStream correctly.

SSRS local report fails - error "An error has occurred during report processing"

I am running ReportViewer 10 using a local report (rdl) file in an MVC web site. I am passing in a DataSet that has the correct data with column names that match the report definition.
var reportDataSource = new ReportDataSource("dataset1", resultSet);
ReportViewer1.LocalReport.ReportPath = Server.MapPath("/Reports/Report2.rdl");
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
List<ReportParameter> lst = new List<ReportParameter>();
ReportParameter rptParam1 = new ReportParameter("Id", "54");
lst.Add(rptParam1);
ReportViewer1.LocalReport.SetParameters(lst);
ReportViewer1.LocalReport.Refresh();
The error I am getting is:
I am unable to find any more specific information on the exact error.
Is there a log file somewhere I can look at?
Thank you.
it turns out that the name of the dataset must match the named defined in the report file exactly including case.
var reportDataSource = new ReportDataSource("dataset1", resultSet);
Becomes:
var reportDataSource = new ReportDataSource("DataSet1", resultSet);