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

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

报告相同问题?