如何调整现有脚本以使文本居中?

时间:2019-05-25 10:20:22

标签: centering

我必须强调,我不是开发人员。我运行了一个名为“ F1 Revisited”的游戏,我的一个朋友为我设计了一些代码,使我可以单击一个按钮在比赛之间重置工作表。

但是,该朋友不再可以在此方面为我提供支持,这让我发疯,使您在重置工作表时,单元格中的文本未居中。我想了解如何改编代码(我足够了解如何访问和修改代码,但我对语法等一无所知!)因此,当我单击“重置”时,“限定”表中每个单元格中的文本(甚至在可能的情况下甚至是整个工作簿!)也都可以居中对齐。

尚未尝试任何操作,因为我对编码一无所知,也不想通过添加不正确的内容来破坏代码的完整性!值得注意的是,单击“重置”后,我可以使文本居中,但可以进行CTRL + A并选择“中心文本”选项-但是要在每个赛季进行26个不同工作表的10多次比赛,这确实是一个痛苦!每次我单击“重置”时,许多单元格都将其完全覆盖。

代码如下:

function resetGame() {


  var LapsReset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('H22')
   LapsReset.setValue(0)
  var TimeReset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('B16')
   TimeReset.setValue(0)
  var SetupMask = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('D25:BL26')
   SetupMask.clearContent()
  var Setups = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('D18:BL19')
   Setups.clearContent()
  var ForColour = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('D18').getBackground()

  var ClrRange = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('E18:BL19')
  var BluBG = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('A1').getBackground()

  ClrRange.clearFormat()
          .setBackground(BluBG)


  var CornerNum = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('B34').getValue()
  var MakeRange = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange(18,4,2,CornerNum)

  MakeRange.setBackground(ForColour)



  var Lap1Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K3')
var Lap2Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K4')
var Lap3Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K5')
var Lap4Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K6')
var Lap5Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K7')
var Lap6Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K8')
var Lap7Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K9')
var Lap8Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K10')
var Lap9Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K11')
var Lap10Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('K12')
var Lap11Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M3')
var Lap12Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M4')
var Lap13Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M5')
var Lap14Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M6')
var Lap15Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M7')
var Lap16Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M8')
var Lap17Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M9')
var Lap18Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M10')
var Lap19Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M11')
var Lap20Reset = SpreadsheetApp.getActive().getSheetByName('Qualifying').getRange('M12')

Lap20Reset.setFormula("=IF('Workings Out'!X49=0,10000,'Workings Out'!X49)")
Lap19Reset.setFormula("=IF('Workings Out'!X48=0,10000,'Workings Out'!X48)")
Lap18Reset.setFormula("=IF('Workings Out'!X47=0,10000,'Workings Out'!X47)")
Lap17Reset.setFormula("=IF('Workings Out'!X46=0,10000,'Workings Out'!X46)")
Lap16Reset.setFormula("=IF('Workings Out'!X45=0,10000,'Workings Out'!X45)")
Lap15Reset.setFormula("=IF('Workings Out'!X44=0,10000,'Workings Out'!X44)")
Lap14Reset.setFormula("=IF('Workings Out'!X43=0,10000,'Workings Out'!X43)")
Lap13Reset.setFormula("=IF('Workings Out'!X42=0,10000,'Workings Out'!X42)")
Lap12Reset.setFormula("=IF('Workings Out'!X41=0,10000,'Workings Out'!X41)")
Lap11Reset.setFormula("=IF('Workings Out'!X40=0,10000,'Workings Out'!X40)")
Lap10Reset.setFormula("=IF('Workings Out'!X39=0,10000,'Workings Out'!X39)")
Lap9Reset.setFormula("=IF('Workings Out'!X38=0,10000,'Workings Out'!X38)")
Lap8Reset.setFormula("=IF('Workings Out'!X37=0,10000,'Workings Out'!X37)")
Lap7Reset.setFormula("=IF('Workings Out'!X36=0,10000,'Workings Out'!X36)")
Lap6Reset.setFormula("=IF('Workings Out'!X35=0,10000,'Workings Out'!X35)")
Lap5Reset.setFormula("=IF('Workings Out'!X34=0,10000,'Workings Out'!X34)")
Lap4Reset.setFormula("=IF('Workings Out'!X33=0,10000,'Workings Out'!X33)")
Lap3Reset.setFormula("=IF('Workings Out'!X32=0,10000,'Workings Out'!X32)")
Lap2Reset.setFormula("=IF('Workings Out'!X31=0,10000,'Workings Out'!X31)")
Lap1Reset.setFormula("=IF('Workings Out'!X30=0,10000,'Workings Out'!X30)")
}

代码现在可以正常工作,除了文本居中的问题。只需知道要添加什么编码以及在哪里确保整个资格表(甚至理想情况下是工作簿)就可以集中文本即可!

任何帮助将不胜感激。

干杯, 乔恩

0 个答案:

没有答案