Guide to SaveResult Task Operations
Introduction
In this tutorial, you’ll learn how to use the SaveResult task in Aspose.Cells Cloud API to manage the output of your spreadsheet processing operations. The SaveResult task is a critical component that allows you to control where and how the results of your API operations are saved or returned to the client.
Prerequisites
Before starting this tutorial, make sure you have:
- An Aspose Cloud account (sign up for free here)
- Your Client ID and Client Secret from the Aspose Cloud dashboard
- Basic understanding of REST API concepts
- Completed at least one of our other task tutorials (recommended)
Understanding the SaveResult Task
The SaveResult task requires two key pieces of information:
ResultSource - Where to find the result file:
- InMemoryFiles: Files that were created or modified in the current task sequence
- Response: Direct response from a previous task
ResultDestination - Where to save or send the result:
- CloudFileSystem: Save to your Aspose Cloud storage
- OutputStream: Return in the API response
- Local: Save to local storage (server-side, for internal use)
Tutorial: Saving Results to Cloud Storage
Let’s create a workflow that performs operations and then saves the results to your Aspose Cloud storage.
Step 1: Structure Your Basic SaveResult Request
<TaskDescription>
<TaskType>SaveResult</TaskType>
<SaveResultTaskParameter>
<ResultSource>InMemoryFiles</ResultSource>
<ResultDestination>
<DestinationType>CloudFileSystem</DestinationType>
<InputFile>ProcessedFile.xlsx</InputFile>
<OutputFile>Results/FinalOutput.xlsx</OutputFile>
</ResultDestination>
</SaveResultTaskParameter>
</TaskDescription>
Step 2: Incorporate in a Complete Workflow
Let’s see how the SaveResult task fits into a complete workflow, where we first import data and then save the result:
<TaskData>
<Tasks>
<!-- First task: Import data into a spreadsheet -->
<TaskDescription>
<TaskType>ImportData</TaskType>
<ImportDataTaskParameter>
<Workbook>
<FileSourceType>CloudFileSystem</FileSourceType>
<FilePath>Template.xlsx</FilePath>
</Workbook>
<ImportBatchDataOption>
<DestinationWorksheet>Sheet1</DestinationWorksheet>
<IsInsert>true</IsInsert>
<BatchData>
<!-- Sample data cells -->
<CellValue>
<rowIndex>0</rowIndex>
<columnIndex>1</columnIndex>
<type>String</type>
<value>Value</value>
</CellValue>
<CellValue>
<rowIndex>1</rowIndex>
<columnIndex>0</columnIndex>
<type>String</type>
<value>Product A</value>
</CellValue>
<CellValue>
<rowIndex>1</rowIndex>
<columnIndex>1</columnIndex>
<type>Double</type>
<value>25.50</value>
</CellValue>
</BatchData>
</ImportBatchDataOption>
</ImportDataTaskParameter>
</TaskDescription>
<!-- Second task: Save the result to cloud storage -->
<TaskDescription>
<TaskType>SaveResult</TaskType>
<SaveResultTaskParameter>
<ResultSource>InMemoryFiles</ResultSource>
<ResultDestination>
<DestinationType>CloudFileSystem</DestinationType>
<InputFile>Template.xlsx</InputFile>
<OutputFile>Processed/DataImport_Result.xlsx</OutputFile>
</ResultDestination>
</SaveResultTaskParameter>
</TaskDescription>
</Tasks>
</TaskData>
Step 3: Execute the API Request
Using cURL
curl -X POST "https://api.aspose.cloud/v3.0/cells/task/runtask" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d "YOUR_XML_REQUEST"
Understanding the Result
After executing the request:
- The ImportData task loads your template and adds data to it
- The SaveResult task stores the modified file in your Aspose Cloud storage under the “Processed” folder with the name “DataImport_Result.xlsx”
- The API response confirms the operation’s success
Tutorial: Returning Results in the API Response
Sometimes you want to get the processed file directly in your API response rather than saving it to cloud storage.
Step 1: Configure the SaveResult Task for Response Output
<TaskDescription>
<TaskType>SaveResult</TaskType>
<SaveResultTaskParameter>
<ResultSource>InMemoryFiles</ResultSource>
<ResultDestination>
<DestinationType>OutputStream</DestinationType>
<InputFile>ProcessedWorkbook.xlsx</InputFile>
<OutputFile>Result.xlsx</OutputFile>
</ResultDestination>
</SaveResultTaskParameter>
</TaskDescription>
Step 2: Handle the Binary Response
When you use OutputStream
as the destination type, the API response will contain the binary data of your file. Your client code needs to handle this appropriately.
Using C# to Process the Response
var xml = @"<TaskData>
<!-- Your tasks XML here -->
</TaskData>";
ServiceHelper helper = new ServiceHelper(sid, key);
using (HttpWebResponse response = helper.CallPost("https://api.aspose.cloud/v3.0/cells/task/runtask", xml, "application/xml"))
{
if (response.StatusCode == HttpStatusCode.OK)
{
System.Console.WriteLine("OK");
Stream st = response.GetResponseStream();
FileStream fs = new FileStream("Result.xlsx", FileMode.OpenOrCreate);
st.CopyTo(fs);
}
}
Advanced: Multiple SaveResult Operations
You can save the results of your operations to multiple destinations. For example, you might want to:
- Save a copy to your cloud storage for archiving
- Return the file in the response for immediate use
<TaskData>
<Tasks>
<!-- Your processing tasks here -->
<!-- Save to cloud storage -->
<TaskDescription>
<TaskType>SaveResult</TaskType>
<SaveResultTaskParameter>
<ResultSource>InMemoryFiles</ResultSource>
<ResultDestination>
<DestinationType>CloudFileSystem</DestinationType>
<InputFile>ProcessedFile.xlsx</InputFile>
<OutputFile>Archive/Processed_2023-09-15.xlsx</OutputFile>
</ResultDestination>
</SaveResultTaskParameter>
</TaskDescription>
<!-- Return in response -->
<TaskDescription>
<TaskType>SaveResult</TaskType>
<SaveResultTaskParameter>
<ResultSource>InMemoryFiles</ResultSource>
<ResultDestination>
<DestinationType>OutputStream</DestinationType>
<InputFile>ProcessedFile.xlsx</InputFile>
<OutputFile>Response.xlsx</OutputFile>
</ResultDestination>
</SaveResultTaskParameter>
</TaskDescription>
</Tasks>
</TaskData>
Saving Different File Formats
The SaveResult task works with any file format produced by previous tasks, not just Excel files. You can save PDFs, images, CSV files, etc.
Example: Saving a PDF Conversion Result
<TaskData>
<Tasks>
<!-- Convert Excel to PDF -->
<TaskDescription>
<TaskType>Convert</TaskType>
<ConvertTaskParameter>
<Workbook>
<FileSourceType>CloudFileSystem</FileSourceType>
<FilePath>Source.xlsx</FilePath>
</Workbook>
<DestinationFile>Temp.pdf</DestinationFile>
</ConvertTaskParameter>
</TaskDescription>
<!-- Save the PDF result -->
<TaskDescription>
<TaskType>SaveResult</TaskType>
<SaveResultTaskParameter>
<ResultSource>InMemoryFiles</ResultSource>
<ResultDestination>
<DestinationType>OutputStream</DestinationType>
<InputFile>Temp.pdf</InputFile>
<OutputFile>Output.pdf</OutputFile>
</ResultDestination>
</SaveResultTaskParameter>
</TaskDescription>
</Tasks>
</TaskData>
Common Issues and Troubleshooting
Issue: File Not Found
If you get a “file not found” error:
- Check that the InputFile name exactly matches the file created by previous tasks
- Verify that the previous tasks successfully completed
- Ensure the file path structure is correct
Issue: Permission Denied
If you get permission issues when saving to cloud storage:
- Verify your access token has the necessary permissions
- Check that the destination folder exists in your cloud storage
- Ensure you’re not trying to overwrite a read-only file
Best Practices for SaveResult
- Consistent Naming Conventions: Use a consistent naming scheme for your output files
- Folder Organization: Organize files in your cloud storage with descriptive folder names
- Error Handling: Always check the API response for success or error information
- Temporary Files: Use the InMemoryFiles source for intermediate results that don’t need to be permanently stored
- Unique Filenames: Use timestamps or GUIDs in filenames to avoid overwriting existing files
Try It Yourself
Create a workflow that:
- Imports data into a spreadsheet
- Converts it to PDF
- Saves both the Excel and PDF versions to cloud storage
Implement a workflow that:
- Loads an Excel file
- Performs multiple operations
- Returns the result directly in the response
What You’ve Learned
In this tutorial, you’ve learned:
- How to save task results to your Aspose Cloud storage
- Methods for returning processed files directly in API responses
- Techniques for managing different file types with SaveResult
- How to chain SaveResult with other tasks for complete workflows
- Best practices for file organization and naming
Further Practice
- Create a scheduled task that processes files and saves them with date-stamped names
- Implement a workflow that processes a file and saves the results in multiple formats
- Build an archiving system that organizes files by date and type in your cloud storage
Next Steps
Now that you’ve mastered saving results, you might want to explore other Aspose.Cells Cloud API capabilities:
- SmartMarker Task Tutorial for template-based document generation
- CellsObjectOperate Task Tutorial for advanced Excel object operations