forked from caenrigen/LatexKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Export.js
68 lines (60 loc) · 2.6 KB
/
Export.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function menuMakeTabular(){
singleExport({groupSettingsGetter: 'getTabs',defaultUserSettingsArrayGetter:'getTabUserDefault',defaultSettingsArrayGetter: 'getTabDefault',strGenerator: range_to_string});
}
function menuExportAllTabs(){
var settings = updateSettingsSheet();
exportGroup(settings.getTabs(),range_to_string);
}
function menuExportData(){
singleExport({groupSettingsGetter: 'getData',defaultUserSettingsArrayGetter:'getDatumUserDefault',defaultSettingsArrayGetter: 'getDatumDefault',strGenerator: datumToStr});
}
function menuExportAllData(){
var settings = updateSettingsSheet();
exportGroup(settings.getData(),datumToStr);
}
function alertExportToFile(str)
{
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Export to file?', str, ui.ButtonSet.YES_NO);
if (response === ui.Button.YES) exportTextToFile(str);
}
function getFullA1Notation(range){
return range.getSheet().getName()+ '!' + range.getA1Notation();
}
function singleExport(obj){
var ss = SpreadsheetApp.getActiveSpreadsheet(),
settingsSh = ss.getSheetByName(getDevSettings().getSettingsSheetName());
var activeRange = ss.getActiveSheet().getActiveRange();
if(settingsSh !== null){
var settings = updateSettingsSheet();
if(getGeneralSettingsFromArray(settings.getGeneral()).getUseSettingForSingleExport() === true){
var activeRangeA1 = getFullA1Notation(activeRange),
groupSettings = settings[obj.groupSettingsGetter](),
namedRanges = ss.getNamedRanges(),
namedRangesLen = namedRanges.length;
for(var i=0;i<namedRangesLen;i++){
var range = namedRanges[i].getRange();
// Check if a named range is active
if(getFullA1Notation(namedRanges[i].getRange()) === activeRangeA1){
for(var j=0;j<groupSettings.length;j++){
// Check if the named range (that is active) has the same name as any in the settings sheet
if(namedRanges[i].getName() === getSettingsFromArray(groupSettings[j]).getRangeName()){
var settingsArray = groupSettings[j];
break;
}
}
}
}
if(settingsArray === undefined) settingsArray = settings[obj.defaultUserSettingsArrayGetter]();
}
}
if(settingsArray === undefined){
alertExportToFile(obj.strGenerator({range: activeRange,
settingsArray: getDefaultSettings()[obj.defaultSettingsArrayGetter]()}));
}else if(settingsArray[0] === "default"){
alertExportToFile(obj.strGenerator({range: activeRange,
settingsArray: settingsArray}));
}else{
exportGroup([settingsArray],obj.strGenerator);
}
}