Swift API 将 TXT 转换为 MHTML

将 TXT 转换为 MHTML 的 Swift 库

使用 Cells Conversion REST API 在 Swift 中创建自定义电子表格工作流程。这是使用 Swift 在线将 TXT 转换为 MHTML 和其他文档格式的专业解决方案。

在 Swift 中将 TXT 文件转换为 MHTML

API
PUT
https://api.aspose.cloud/v3.0/cells/convert

将文件格式从 TXT 转换为 MHTML 是一项复杂的任务。所有 TXT 到 MHTML 格式的转换均由我们的 Swift SDK 执行,同时保留源 TXT 电子表格的主要结构和逻辑内容。我们的 Swift 库是在线将 TXT 转换为 MHTML 文件的专业解决方案。此 Cloud SDK 为 Swift 开发人员提供了强大的功能和完美的 MHTML 输出。

Swift 中使用 REST API 将 TXT 转换为 MHTML 格式的代码示例

// For complete examples and data files, please go to https://github.com/aspose-cells-cloud/aspose-cells-cloud-swift/
    import AsposeCellsCloud
    let expectation1 = self.expectation(description: "checkAuth")
    AsposeCellsCloudAPI.clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    AsposeCellsCloudAPI.clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    AuthAspose.checkAuth()
    {
        (authError) in
        guard authError == nil else {
            XCTFail("error checkAuth")
            return
        }
        expectation1.fulfill()
    }
    self.waitForExpectations(timeout: testTimeout, handler: nil)        
    let expectation = self.expectation(description: "PutConvert")
    let workbook:String = "Book1.txt"
    let format:String? = "mhtml"     
    let url1: URL? = getURL(workbook)
    let filedata = NSData(contentsOfFile: url1!.path)
    let password:String? = nil
    let outPath:String? = nil
    CellsAPI.cellsWorkbookPutConvertWorkbook(file: url1!, format: format, password: password, outPath: outPath)
    {
        (response, error) in
        guard error == nil else {
            let errorinfo = self.GetErrorDataInfo(error: error as! ErrorResponse)
            print("error info: \(errorinfo!)")
            XCTFail("error PutConvert")
            return
        }            
        if let response = response {
            //response is a Data of file, we may write it down and check it.
            let fileName = "dest.mhtml"
            let filePath = NSHomeDirectory()
            let fileManager = FileManager.default
            let path = "\(filePath)/tmp/\(fileName)"
            fileManager.createFile(atPath: path, contents:nil, attributes:nil)
            let handle = FileHandle(forWritingAtPath:path)
            handle?.write(response as Data)
            expectation.fulfill()
        }
    }
    self.waitForExpectations(timeout: testTimeout, handler: nil)


如何使用 Swift API 将 TXT 转换为 MHTML

  1. 创建一个帐户仪表板获取免费API配额和授权详细信息
  2. 使用客户端 ID、客户端密码、基本 URL 和 API 版本初始化 CellsApi
  3. 调用 cellsWorkbookPutConvertWorkbook 方法来获取结果流


系统要求

  1. macOS 蒙特利 12.4
  2. 斯威夫特 4.2