Skip to content

Instantly share code, notes, and snippets.

@stormwild
Last active July 19, 2024 19:42
Show Gist options
  • Save stormwild/7487156fbb1b02cb3f3bb507a9c89eb1 to your computer and use it in GitHub Desktop.
Save stormwild/7487156fbb1b02cb3f3bb507a9c89eb1 to your computer and use it in GitHub Desktop.
Aspose

Aspose

aspose-cells/Aspose.Cells-for-.NET: Aspose.Cells for .NET examples, plugins and showcases

Yes, you can use Aspose with your .NET 6 web API to generate Excel reports, PDFs, and Word documents. Aspose.Total for .NET provides comprehensive libraries like Aspose.Cells for Excel, Aspose.PDF for PDF, and Aspose.Words for Word documents. These libraries allow you to create, manipulate, convert, and render various document formats programmatically without the need for external dependencies like Microsoft Office.

You can find more details and get started by visiting Aspose.Total for .NET.

Here are simple "Hello World" examples for generating Excel, PDF, and Word documents using Aspose.Total for .NET:

1. Excel (using Aspose.Cells)

using Aspose.Cells;

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Cells["A1"].PutValue("Hello World");
workbook.Save("HelloWorld.xlsx");

2. PDF (using Aspose.PDF)

using Aspose.Pdf;
using Aspose.Pdf.Text;

Document pdfDocument = new Document();
Page page = pdfDocument.Pages.Add();
page.Paragraphs.Add(new TextFragment("Hello World"));
pdfDocument.Save("HelloWorld.pdf");

3. Word (using Aspose.Words)

using Aspose.Words;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello World");
doc.Save("HelloWorld.docx");

Steps to Set Up

  1. Install the necessary Aspose libraries via NuGet:
Install-Package Aspose.Cells
Install-Package Aspose.Pdf
Install-Package Aspose.Words
  1. Use the above code snippets in your .NET 6 web API project.

These examples create a basic document and save it to the file system. You can expand on these to fit more complex requirements.

In aspose cell how can I add a table using a list or dataset?

To add a table in Aspose.Cells using a list or dataset, you can follow these steps:

Using a List

using Aspose.Cells;
using System.Collections.Generic;

// Sample data
var data = new List<string[]>
{
    new string[] { "Name", "Age", "Gender" },
    new string[] { "John Doe", "30", "Male" },
    new string[] { "Jane Doe", "28", "Female" }
};

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

// Fill data
for (int i = 0; i < data.Count; i++)
{
    for (int j = 0; j < data[i].Length; j++)
    {
        sheet.Cells[i, j].PutValue(data[i][j]);
    }
}

// Create table
ListObject listObject = sheet.ListObjects[sheet.ListObjects.Add(0, 0, data.Count - 1, data[0].Length - 1, true)];
listObject.TableStyleType = TableStyleType.TableStyleMedium9;

workbook.Save("TableFromList.xlsx");

Using a DataSet:

using Aspose.Cells;
using System.Data;

// Sample DataSet
DataSet dataSet = new DataSet();
DataTable dataTable = new DataTable("SampleTable");
dataTable.Columns.Add("Name", typeof(string));
dataTable.Columns.Add("Age", typeof(int));
dataTable.Columns.Add("Gender", typeof(string));

dataTable.Rows.Add("John Doe", 30, "Male");
dataTable.Rows.Add("Jane Doe", 28, "Female");

dataSet.Tables.Add(dataTable);

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

// Import DataTable to worksheet
sheet.Cells.ImportDataTable(dataTable, true, 0, 0);

// Create table
ListObject listObject = sheet.ListObjects[sheet.ListObjects.Add(0, 0, dataTable.Rows.Count, dataTable.Columns.Count - 1, true)];
listObject.TableStyleType = TableStyleType.TableStyleMedium9;

workbook.Save("TableFromDataSet.xlsx");

Steps

  1. Install Aspose.Cells via NuGet:
Install-Package Aspose.Cells
  1. Use the above code snippets in your .NET 6 web API project to create Excel tables from lists or datasets.

I can't seem to find information on using Aspose that was written or published in the last two years. Can you list any tutorials that show how to use Aspose with .NET 6 or higher

Here are some tutorials and resources for using Aspose with .NET 6 or higher to generate Excel, PDF, and Word documents:

1. Aspose.Cells for .NET

  • Official Documentation: The Aspose.Cells for .NET documentation provides detailed information on how to create, manipulate, and convert Excel files. It includes examples for working with tables, charts, and other Excel features.
  • Code Samples: You can find practical code samples on their GitHub repository.
  • Tutorial: A step-by-step tutorial on creating an Excel file and adding a table using .NET 6 is available in the Aspose.Cells documentation.

2. Aspose.PDF for .NET

  • Official Documentation: The Aspose.PDF for .NET documentation covers various operations you can perform with PDF files, including creation, manipulation, and conversion.
  • Features Tutorial: A comprehensive tutorial on working with PDF files, including adding tables, can be found on the Aspose website.
  • Code Samples: Practical examples for manipulating PDFs are available on their GitHub repository.

3. Aspose.Words for .NET

  • Official Documentation: The Aspose.Words for .NET documentation offers extensive guides on creating, editing, and converting Word documents.
  • Code Samples: You can find examples on their GitHub repository for common tasks like inserting text, images, and tables.
  • Tutorial: A detailed tutorial on generating Word documents using .NET 6 is available in the Aspose.Words documentation.

Example Code Snippets

Creating an Excel Table from a List

using Aspose.Cells;
using System.Collections.Generic;

// Sample data
var data = new List<string[]>
{
    new string[] { "Name", "Age", "Gender" },
    new string[] { "John Doe", "30", "Male" },
    new string[] { "Jane Doe", "28", "Female" }
};

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

// Fill data
for (int i = 0; i < data.Count; i++)
{
    for (int j = 0; j < data[i].Length; j++)
    {
        sheet.Cells[i, j].PutValue(data[i][j]);
    }
}

// Create table
ListObject listObject = sheet.ListObjects[sheet.ListObjects.Add(0, 0, data.Count - 1, data[0].Length - 1, true)];
listObject.TableStyleType = TableStyleType.TableStyleMedium9;

workbook.Save("TableFromList.xlsx");

Creating a PDF Document:

using Aspose.Pdf;
using Aspose.Pdf.Text;

Document pdfDocument = new Document();
Page page = pdfDocument.Pages.Add();
page.Paragraphs.Add(new TextFragment("Hello World"));
pdfDocument.Save("HelloWorld.pdf");

Creating a Word Document:

using Aspose.Words;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello World");
doc.Save("HelloWorld.docx");

These examples illustrate the basic usage of Aspose libraries with .NET 6. For more advanced features and comprehensive tutorials, refer to the official documentation and code samples provided by Aspose (Aspose Documentation) (File Format APIs) (File Format APIs) (Visual Studio Marketplace).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment