Komma igång

Installation

Installera Aspose.Cells genom NuGet

NuGet är det enklaste sättet att ladda ner och installera Aspose.Cells for .NET.

  1. Öppna Microsoft Visual Studio och NuGet-paket hanterare.
  2. Sök efter “aspose.cells” för att hitta önskad Aspose.Cells for .NET.
  3. Klicka på “Installera”, Aspose.Cells for .NET kommer att laddas ner och refereras i ditt projekt. Installera Aspose Cells genom NuGet

Du kan också ladda ner den från nuget-webbsidan för aspose.cells: Aspose.Cells for .NET NuGet-paket

Fler steg för detaljer

Installera Aspose.Cells på Windows

  1. Ladda ner Aspose.Cells.msi från följande sida: Ladda ner Aspose.Cells.msi
  2. Dubbelklicka på Aspose Cells msi och följ anvisningarna för att installera den:

Installera Aspose Cells på windows

Fler steg för detaljer

Installera Aspose.Cells på linux

I det här exemplet använder jag Ubuntu för att visa hur du börjar använda Aspose.Cells på linux.

  1. Skapa en .netcore-applikation med namnet “AsposeCellsTest”.
  2. Öppna filen “AsposeCellsTest.csproj”, lägg till följande rader i den för Aspose.Cells-paketreferenser:
      <ItemGroup>
        <PackageReference Include="Aspose.Cells" Version="24.7" />
      </ItemGroup>
  3. Öppna projektet med VSCode på Ubuntu: Installera Aspose Cells på linux
  4. kör testet med följande kod:
    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
    Aspose.Cells.Workbook wb1 = new Aspose.Cells.Workbook();
    wb1.Worksheets.Add("linux");
    wb1.Worksheets["linux"].Cells[0, 0].Value = "Using Aspose Cells on linux with VS Code.";
    wb1.Save("linux.xlsx");

Obs! Aspose.Cells för .NetStandard kan stödja dina krav på linux.

Gäller för: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 och avancerad version.

Installera Aspose.Cells på MAC OS

I det här exemplet använder jag macOS High Sierra för att visa hur du börjar använda Aspose.Cells på MAC OS.

  1. Skapa en .netcore-applikation med namnet “AsposeCellsTest”.
  2. Öppna applikationen med Visual Studio för Mac, sedan installera Aspose Cells via NuGet: Installera Aspose Cells på macOS
  3. kör testet med följande kod:
    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
    Aspose.Cells.Workbook wb1 = new Aspose.Cells.Workbook();
    wb1.Worksheets.Add("macOS");
    wb1.Worksheets["macOS"].Cells[0, 0].Value = "Using Aspose Cells on macOS with Visual Studio For MAC.";
    wb1.Save("macOS.xlsx");
  4. Om du behöver använda ritrelaterade funktioner, installera libgdiplus i macOS, se: Hur man installerar libgdiplus i macOS

Obs! Aspose.Cells för .NetStandard kan stödja dina krav på MAC OS.

Gäller för: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 och avancerad version.

Run Aspose Cells in Docker

Hur man använder grafikbibliotek på icke-Windows-plattformar med Net6

Aspose.Cells för Net6 använder nu SkiaSharp som grafikbibliotek, som rekommenderas i Microsofts officiella uttalande. För mer information om att använda Aspose.Cells med NET6, se Hur man kör Aspose.Cells för .Net6.

Skapa Hello World-applikationen

Följande steg skapar Hello World-applikationen med Aspose.Cells API:

  1. Om du har en licens, ansök om den. Om du använder utvärderingsversionen, hoppa över licensrelaterade kodrader.
  2. Skapa en instans av klassen Workbook för att skapa en ny Excel-fil eller öppna en befintlig Excel-fil.
  3. Åtkomst till valfri cell i ett kalkylblad i Excel-filen.
  4. Infoga orden Hello World! i en åtkomstcell.
  5. Generera den modifierade Microsoft Excel-filen.

Implementeringen av ovanstående steg visas i exemplen nedan.

Kodexempel: Skapa en ny arbetsbok

Det följande exemplet skapar en ny arbetsbok från grunden, infogar “Hello World!” i cell A1 i den första kalkylbladet och sparar den som Excel-fil.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
try
{
// Create a License object
License license = new License();
// Set the license of Aspose.Cells to avoid the evaluation limitations
license.SetLicense(dataDir + "Aspose.Cells.lic");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// Instantiate a Workbook object that represents Excel file.
Workbook wb = new Workbook();
// When you create a new workbook, a default "Sheet1" is added to the workbook.
Worksheet sheet = wb.Worksheets[0];
// Access the "A1" cell in the sheet.
Cell cell = sheet.Cells["A1"];
// Input the "Hello World!" text into the "A1" cell
cell.PutValue("Hello World!");
// Save the Excel file.
wb.Save(dataDir + "MyBook_out.xlsx");

Kodexempel: Öppna en befintlig fil

Följande exempel öppnar en befintlig Microsoft Excel-mal fil “Prov.xlsx”, sätter in “Hej världen!” i cell A1 i det första kalkylarket och sparar som Excel fil.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
try
{
// Create a License object
License license = new License();
// Set the license of Aspose.Cells to avoid the evaluation limitations
license.SetLicense("Aspose.Cells.lic");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "Sample.xlsx", FileMode.Open);
// Instantiate a Workbook object that represents the existing Excel file
Workbook workbook = new Workbook(fstream);
// Get the reference of "A1" cell from the cells collection of a worksheet
Cell cell = workbook.Worksheets[0].Cells["A1"];
// Put the "Hello World!" text into the "A1" cell
cell.PutValue("Hello World!");
// Save the Excel file
workbook.Save(dataDir + "HelloWorld_out.xlsx");
// Closing the file stream to free all resources
fstream.Close();