douxi3233 2017-11-18 13:24
浏览 14
已采纳

在写入之前清空谷歌工作表

I use the asimlqt/php-google-spreadsheet-client to read google spreadsheets and to write in google spreadsheets.

There are functions to update and delete the actual worksheet but not to empty the worksheet before i write data in it.
Knows somebody who use this library a way to empty the worksheet before writing in? If not you can not be sure that old data is still available

  • 写回答

1条回答 默认 最新

  • dsai1991 2017-11-18 13:42
    关注

    My personal solution is delete the worksheet and recreate

    // service
    $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
    $spreadsheetFeed = $spreadsheetService->getSpreadsheetFeed();
    
    // retrieve a list of worksheets from a spreadsheet 
    $spreadsheet = $spreadsheetFeed->getByTitle('Spreadsheet');
    $worksheetFeed = $spreadsheet->getWorksheetFeed();
    
    // get the worksheet you want to empty
    $worksheet = $worksheetFeed->getByTitle('EmptySheet');
    
    // delete the worksheet
    $worksheet->delete();
    
    // recreate the worksheet to be sure it's empty
    $spreadsheet->addWorksheet('EmptySheet', rows, column);
    

    Edit

    Or use the batchUpdate with empty param userEnteredValue. Look at https://developers.google.com/sheets/api/samples/sheet#clear_a_sheet_of_all_values_while_preserving_formats

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog