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

图片转代码服务由CSDN问答提供 功能建议

我使用 asimlqt / php-google-spreadsheet-client 阅读谷歌电子表格并写入谷歌电子表格。 \ n

有一些函数可以更新和删除实际的工作表,但是在我写入数据之前不要清空工作表。
如果有人在写入之前使用这个库来清空工作表? 如果不是,您无法确定旧数据是否仍然可用

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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

    点赞 打赏 评论

相关推荐 更多相似问题