How to add line break to labels on axis for IE9? - dojo

I'm using Dojo 1.9.1.
I'm using dojox.charting to draw some charts.
I am using a labelFunc to produce a date/time label for my X-axis. This is working fine in all browsers.
But I want to add a line break to my label so that the date sits above the time, e.g.:
10/01/2014
06:00
I can add a html break tag to the string returned and this works in Chrome and Firefox but not IE9 (to be expected).
Has anybody solved how to do this one that works across all browsers including IE9 (or specifically ones that don't "do" html labels).
Cheers
Ian
My label func:
_labelFull: function (index) {
// Returns a label in the form "dd/mm/yyyy hh:mm" for tooltip labelling
var dt,
d;
dt = new Date(Date.parse(myglobalStartDateTime));
dt.setHours(dt.getHours() + Number(index));
// Full date/time
d = ("0" + dt.getDate()).slice(-2) + '/' +
("0" + (dt.getMonth() + 1)).slice(-2) + '/' +
dt.getFullYear() + ' ' +
("0" + dt.getHours()).slice(-2) + ':' +
("0" + dt.getMinutes()).slice(-2) + 'UTC';
return d;
}

Related

Create Google Script that saves sheet as pdf to specified folder in google drive

So thanks to other members I was able to piece together a script that does what I need except for 1 small hiccup. Rather than saving the single sheet as a pdf in the designated folder, it saves the entire workbook. I've tried multiple variations to get it to save just the sheet I want (named JSA) but it either gives me an error message or continues to download the whole spreadsheet. I'm sure it's something simple I'm missing, but I'm not as versed with Script as I am with writing Macros, so I'm stuck. The first part of the code, downloading it as a PDF works like a charm, it's the last section where I want it to save the PDF to a specified folder that's the issue. Any assistance would be appreciated.
function downloadPdf() {
var ss = SpreadsheetApp.getActive(),
id = ss.getId(),
sht = ss.getActiveSheet(),
shtId = sht.getSheetId(),
url =
'https://docs.google.com/spreadsheets/d/' +
id +
'/export' +
'?format=pdf&gid=' +
shtId
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=false' // orientation, false for landscape
+ '&scale=2' // 1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
+ '&fitw=true' // fit to width, false for actual size
+ '&top_margin=0.25' // All four margins must be set!
+ '&bottom_margin=0.25' // All four margins must be set!
+ '&left_margin=0.25' // All four margins must be set!
+ '&right_margin=0.25' // All four margins must be set!
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenum=false&gridlines=false' // hide page numbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&horizontal_alignment=CENTER' //LEFT/CENTER/RIGHT
+ '&vertical_alignment=TOP'; //TOP/MIDDLE/
var val = SpreadsheetApp.getActive().getRange('H2').getValues();//custom pdf name here
var val2= Utilities.formatDate(SpreadsheetApp.getActive().getRange("N2").getValue(), ss.getSpreadsheetTimeZone(), "MM/dd/YY");
var val3= " - "
val += val3 += val2 += '.pdf';
//can't download with a different filename directly from server
//download and remove content-disposition header and serve as a dataURI
//Use anchor tag's download attribute to provide a custom filename
var res = UrlFetchApp.fetch(url, {
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
});
SpreadsheetApp.getUi().showModelessDialog(
HtmlService.createHtmlOutput(
'<a target ="_blank" download="' +
val +
'" href = "data:application/pdf;base64,' +
Utilities.base64Encode(res.getContent()) +
'">Click here</a> to download, if download did not start automatically' +
'<script> \
var a = document.querySelector("a"); \
a.addEventListener("click",()=>{setTimeout(google.script.host.close,10)}); \
a.click(); \
</script>'
).setHeight(50),
'Downloading PDF..'
);
const folderName = `Test`;
const fileNamePrefix = val += val3 += val2 += '.pdf';
var JSA = SpreadsheetApp.getActiveSpreadsheet();
var s = JSA.getSheetByName("JSA");
DriveApp.getFoldersByName(folderName)
.next()
.createFile(SpreadsheetApp.getActiveSpreadsheet()
.getBlob()
.getAs(`application/pdf`)
.setName(`${fileNamePrefix}`));
}
I believe your goal is as follows.
You want to create a PDF file, which is downloaded using the first part of your script, in the specific folder on Google Drive.
In this case, how about the following modification? I thought that res might be able to be used.
From:
var JSA = SpreadsheetApp.getActiveSpreadsheet();
var s = JSA.getSheetByName("JSA");
DriveApp.getFoldersByName(folderName)
.next()
.createFile(SpreadsheetApp.getActiveSpreadsheet()
.getBlob()
.getAs(`application/pdf`)
.setName(`${fileNamePrefix}`));
To:
DriveApp.getFoldersByName(folderName)
.next()
.createFile(res.getBlob().setName(`${fileNamePrefix}`));
In this modification, it supposes that sht = ss.getActiveSheet(), is JSA sheet. If the active sheet is not JSA sheet, please modify as follows.
To:
const url2 =
'https://docs.google.com/spreadsheets/d/' +
id +
'/export' +
'?format=pdf&gid=' +
ss.getSheetByName("JSA").getSheetId()
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=false' // orientation, false for landscape
+ '&scale=2' // 1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
+ '&fitw=true' // fit to width, false for actual size
+ '&top_margin=0.25' // All four margins must be set!
+ '&bottom_margin=0.25' // All four margins must be set!
+ '&left_margin=0.25' // All four margins must be set!
+ '&right_margin=0.25' // All four margins must be set!
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenum=false&gridlines=false' // hide page numbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&horizontal_alignment=CENTER' //LEFT/CENTER/RIGHT
+ '&vertical_alignment=TOP'; //TOP/MIDDLE/
const res2 = UrlFetchApp.fetch(url2, {
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
});
DriveApp.getFoldersByName(folderName)
.next()
.createFile(res2.getBlob().setName(`${fileNamePrefix}`));
Reference:
fetch(url, params)

How to get anchor point of SymbolItem

I can't figure out how to retrieve registration point that I see in properties panel transform section in script.
I use this script documentation http://ai.aenhancers.com/jsobjref/SymbolItem/
As far as I can tell they are just coordinates of the symbol's center. You can get them this way:
var symbol = app.activeDocument.selection[0];
var X = symbol.position[0] + symbol.width/2;
var Y = -symbol.position[1] + symbol.height/2;
alert("X: " + X + "\n" + "Y: " + Y);

Google Apps script created file is not PDF

I'm trying to create a PDF file with this code:
var name = "test.pdf";
var url = 'https://docs.google.com/spreadsheets/d/' + newSpreadsheetID + '/export?exportFormat=pdf&format=pdf' +
'&size=A4' +
'&portrait=true' +
'&fitw=true' + // fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false' + // do not repeat frozen rows on each page
'&gid='+SheetID; //the sheet's Id
var pdf = UrlFetchApp.fetch(url);
var pdf = pdf.getBlob().setName(name);
DocsList.createFile(pdf);
This code creates a file but the file contains just plain text, can you guys help me to get it into PDF format?
First off, DocsList was deprecated (https://developers.google.com/apps-script/reference/docs-list/docs-list). So I think we should use DriveApp this time.
I ignored the parameters you used to format the pdf, the script can be simply as -
var sheet = DriveApp.getFileById(spreadsheetId);
DriveApp.createFile(sheet.getAs("application/pdf"));
Please let me know if you want more elaboration. :)
I made a few changes and got your call working. I don't know where the documentation for the export settings are, but some of them don't work such as "gridlines". Also below is a 2 line example of the same thing.
function makePDF(){
var newSpreadsheetID = SpreadsheetApp.getActive().getId()
var SheetID="Sheet1";
var name = "test.pdf";
var url = 'https://docs.google.com/spreadsheets/d/' + newSpreadsheetID + '/export?exportFormat=pdf&format=pdf'; +
'&size=A4' +
'&portrait=true' +
'&fitw=true' + // fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false'; + // do not repeat frozen rows on each page
'&gid='+SheetID; //the sheet's Id
var pdf = UrlFetchApp.fetch(url,{headers: {authentication:"Bearer " + ScriptApp.getOAuthToken()}, muteHttpExceptions:true}).getBlob();
pdf.setName(name);
DriveApp.createFile(pdf);
}
function simplePDFConvert(){
var ss = SpreadsheetApp.openById( spreadSheetId );
DriveApp.createFile(ss.getBlob());
}

Convert Date field while retreiving from Sharepoint list in client object

I am creating a windows forms which loads list items from sharepoint client object model.
I am having issue with Date field which is giving +1 day or -1 day i.e if i have entered date as 5/5/2014 it gives 5/6/2014 or sometimes 5/4/2014.
_query.ViewXml = "<View><Query><Where>" +
"<And><Geq><FieldRef Name='Effort_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>" + conStartDate + "</Value></Geq>" +
"<And><Leq><FieldRef Name='Effort_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>" + conEndDate + "</Value></Leq>" +
"<Eq><FieldRef Name='Author' LookupId=’TRUE’/><Value Type=’Text’>" + UserID + "</Value></Eq></And></And></Where>" +
"<GroupBy Collapse='TRUE'><FieldRef Name='WBS_x0020_Code'/></GroupBy></Query><RowLimit>25</RowLimit></View>";
SP.ListItemCollection _listitems = list.GetItems(_query);
clientcontext.ExecuteQuery();
After executing this if i use the below code it works properly but takes lot of time.
foreach(ListItem item in _listitems) {
DateTime start = ((DateTime) item["Effort_x0020_Date"]);
ClientResult < string > result = Utility.FormatDateTime(clientcontext, clientcontext.Web, start, DateTimeFormat.DateTime);
clientcontext.ExecuteQuery();
DateTime rightStart = Convert.ToDateTime(result.Value, new CultureInfo((int) web.Language));
//item["Effort_x0020_Date"] = rightStart;
}
Somehow i want an alternate way by which this could be done faster so that everytime connecting to sharepoint is avoided.
I resolved the issue by putting
_query.DatesInUtc=false.
It worked!!

Export custom formatted expressions from Mathematica

How can I get Mathematica to export/save/write a text file with proper Fortan77 formatting, that is, 72 columns and a continuation marker on the sixth column?
I am using Mathematica to generate large and complex analytic expressions, which I then need to insert into pre-existing Fortran77 code. I have everything working correctly in the front end of Mathematica with FortranForm[] and
SetOptions[$Output, PageWidth -> 72]
However, I can't figure out how to get Mathematica to output correctly to a text file. I want something like this:
MM11 = mH1**2 + (g2**2*v1**2)/2. -
- (g2**2*(v1**2/2. -
- ((v2*Cos(phi2) - (0,1)*v2*Sin(phi2))*
- (v2*Cos(phi2) + (0,1)*v2*Sin(phi2)))/2.))/2.
...
but get either this:
MM11 = FortranForm[mH1^2 + (g2^2*v1^2)/2 - ...
or this:
MM11 = mH1**2 + (g2**2*v1**2)/2. - (g2**2*
(v1**2/2. - ((v2*Cos(phi2) - (0,1)*v2*Sin(phi2))*
...
This is a job for the surprisingly little-known Splice function. First, you make a template file, with the extension ".mf", like so:
file = "test.mf";
out = OpenWrite[file];
WriteString[out, "MH1 = <* form *>"];
Close[out];
Now when you use Splice, Mathematica will automatically replace everything between the <* and *> delimiters with its evaluated form. So if you set
form = 4 + b9^2 + c1^5 + c4^5 + h10^4 + j2 + k10^4 + p10^4 + q5^5 +
q8 + s3^3 + s7^2 + t6^3 + u3^2 + u9^3 + x8^4 + z2^3;
and call
Splice["test.mf", PageWidth -> 72];
which will automatically infer you want FortranForm output from the file extension, and which allows you to set PageWidth as an option, you will get a pretty decent result in the automatically generated file "test.f" (note the new extension):
MH1 = 4 + b9**2 + c1**5 + c4**5 + h10**4 + j2 + k10**4 + p10**4 +
- q5**5 + q8 + s3**3 + s7**2 + t6**3 + u3**2 + u9**3 + x8**4 +
- z2**3
Look at the docs for Splice for more options (changing the name of the output file and the like).