Add Comment to Cell in Worksheet!

Hi, thanks for all this Aspose awesome products.

I’m having problems when adding comments to some cell in a worksheet (using Swift & AsposeCell pod). I read all the doc and google a loot with no result.

Currently I complete the fallowing task’s.

  • Configure platform with ClientId & ClientSecret
  • Auth with Aspose Cloud Service (getting auth token etc.)
  • Create a new workbook in the cloud (named test.xlsx)
  • Add four cells with value (valueType: int, value: 100) from A1 to D1
  • Add one cell with formula at A2 (=Sum(A1,B1,C1,D1)) and getting in A2 the excepted result (400 in this case)
  • Renamed default worksheet from “Sheet1” to “Start”
  • Add another worksheet (named “Other data”)
  • I’m downloading the file to local file storage & viewing with Microsoft Excel (for MacOS) and is fine (no errors of any type).

I ve created a wrapper with a loot of functions I’m using (I will share this with community when finished) but I have problems with the cellsWorksheetsPostWorksheetComment function. Currently I run this code:

    // Swift code
    let link = Link(href: "/\(self.fileName)/worksheets/\(self.worksheetName)/comments/A2", type: nil, rel: "self", title: nil)
    let comment = Comment(link: link, autoSize: true, author: "Wo_0NDeR", isVisible: true, textOrientationType: "NoRotation", height: 10, note: "This is a note from Wo_0NDeR", width: 10, textVerticalAlignment: "Top", cellName: "A2", htmlNote: "This is a note from Wo_0NDeR", textHorizontalAlignment: "Left")

    CellsAPI.cellsWorksheetsPostWorksheetComment(name: self.fileName, sheetName: self.worksheetName, cellName: "A2", comment: comment) { data, error in
        print(data)
        print(error)
    }

but I’m receiving this error from aspose cell cloud API:

error(400, Optional(264 bytes), Alamofire.AFError.responseValidationFailed(reason: Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(code: 400)))

And from the Api Usage Section in Dashboard I see this log:

Method Name: PostWorksheetComment
Product: Aspose.Cells
API Version: v3.0
Details: Error: PostWorksheetComment. Exception: PostWorkSheetComment fails. (Object reference not set to an instance of an object.).

Some help with this this would be appreciated. Thanks in Advance !

I implement this for Swift from scratch using async/await (with a wrapper). I will be sharing this soon: A example of one of the functions:

@discardableResult
func setCellValue(fileName: String, sheetName: String, cellName: String, value: String, valueType: CellValueType? = .string, formula: String? = nil) async throws -> CellResponse? {
    return try await withCheckedThrowingContinuation({ continuation in

        // If not value type set, assing string by default
        let cellValueType: CellValueType = valueType ?? .string

        CellsAPI.cellsPostWorksheetCellSetValue(name: fileName, sheetName: sheetName, cellName: cellName, value: value, type: cellValueType.rawValue, formula: formula, folder: nil, storageName: nil) { data, error in
            if let error = error {
                continuation.resume(throwing: error)
            } else {
                return continuation.resume(returning: data)
            }
        }
    })
}

A example usage:

let setValueA1 = try await self.asposeCellWrapper.setCellValue(fileName: self.fileName, sheetName: self.worksheetName, cellName: "A1", value: "100", valueType: .int)

@wonderDeveloper,

We will check it asap and reply with checked results.

@wonderDeveloper,

I used Aspose.Cells Cloud SDK for DotNet to simulate your process. And the cell comment can’t be modified when there are no comments on the worksheet cells.

Please check the worksheet comments present in the Excel file.