Getting a merged cell width on Google Spreadsheet API

﹥>﹥吖頭↗ 提交于 2019-12-01 08:22:17

问题


I'm using the Google Spreadsheet API to convert a document containing workers shifts into event calendars. The only problem is that shifts are represented by merged cells according to days and hours (with days and hours as rows and different work slots as cols), and when I read a certain cell, which is merged and spans over 6 cells, I cannot get the cells certain width or its merged area.

For example:

If I try to get the values between (4C:4E) I will get "Bob, , ," and not "bob,bob,bob", and I cannot even find a way to know how many cells "bob" take.

Do you guys know how can I know how many cells the merged one spread to? Or at least it's total width.

Thanks in advance!


回答1:


It's not possible via spreadsheet API. I was looking for same. Google admits the same in their documentation.

The literal value of the cell element is the calculated value of the cell, without formatting applied. If the cell contains a formula, the calculated value is given here. The Spreadsheets API has no concept of formatting, and thus cannot manipulate formatting of cells.

Related question: Set cell format in Google Sheets spreadsheet using its API & Python

One alternate way can be to download the doc in excel format programmatically. It will contain formatting information. Then using excel API to extract the info.




回答2:


Download from google drive as html, see: Get FontStyle information from Google spreadsheet into appengine

    Drive driveService = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential).build();
    File file = driveService.files().get(this.spreadsheetKey).execute();
    String downloadUrl = file.getExportLinks().get("application/pdf");
    downloadUrl = downloadUrl.replaceFirst("exportFormat=pdf", "exportFormat=html");
    downloadUrl = appendWorksheetGid(downloadUrl); // adds "&gid="+sheetGid
    HttpResponse resp =
            driveService.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl))
                .execute();
    System.out.println("downloadUrl:"+downloadUrl);

    InputStream fileContent = resp.getContent();
    extractStyleFromHtml(fileContent,downloadUrl);

extractStyleFromHtml uses Jsoup - (Jsoup impressed me)



来源:https://stackoverflow.com/questions/11599412/getting-a-merged-cell-width-on-google-spreadsheet-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!