Komma igång
Installation
Installera Aspose.Cells till NuGet
NuGet är det enklaste sättet att ladda ner och installera Aspose.Cells for .NET.
- Öppna Microsoft Visual Studio och NuGet pakethanterare.
- Sök “aspose.cells” för att hitta önskad Aspose.Cells for .NET.
- Klicka på “Installera”, Aspose.Cells for .NET kommer att laddas ner och refereras till i ditt projekt.
Du kan också ladda ner den från webbsidan nuget för aspose.cells: Aspose.Cells for .NET NuGet Paket
Installera Aspose.Cells på Windows
- Ladda ner Aspose.Cells.msi från följande sida: Ladda ner Aspose.Cells.msi
- Dubbelklicka på Aspose Cells msi och följ instruktionerna för att installera den:
Installera Aspose.Cells på linux
I det här exemplet använder jag Ubuntu för att visa hur man börjar använda Aspose.Cells på linux.
- Skapa en .netcore-applikation med namnet “AsposeCellsTest”.
- Öppna filen “AsposeCellsTest.csproj”, lägg till följande rader i den för Aspose.Cells paketreferenser:
<ItemGroup> <PackageReference Include="Aspose.Cells" Version="22.12" /> </ItemGroup>
- Öppna projektet med VSCode på Ubuntu:
- kör testet med följande kod:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// 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: 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 man börjar använda Aspose.Cells på MAC OS.
- Skapa en .netcore-applikation med namnet “AsposeCellsTest”.
- Öppna programmet med Visual Studio för Mac och installera sedan Aspose Cells till NuGet:
- kör testet med följande kod:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// 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"); - Om du behöver använda ritningsrelaterade 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: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 och avancerad version.
Kör Aspose Cells i 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 iofficiellt uttalande på Microsoft . För mer information om hur du använder Aspose.Cells med NET6, seHur man kör Aspose.Cells för .Net6.
Skapar Hello World-applikationen
Stegen nedan skapar Hello World-applikationen med hjälp av Aspose.Cells API:
- Om du har en licens, dåtillämpa den. Om du använder utvärderingsversionen, hoppa över de licensrelaterade kodraderna.
- Skapa en instans avArbetsbok klass för att skapa en ny Excel-fil, eller öppna en befintlig Excel-fil.
- Få åtkomst till valfri cell i ett kalkylblad i Excel-filen.
- Sätt in ordenHello World! in i en cell som nås.
- Generera den modifierade Microsoft Excel-filen.
Implementeringen av stegen ovan visas i exemplen nedan.
Kodexempel: Skapa en ny arbetsbok
Följande exempel skapar en ny arbetsbok från början, infogar “Hello World!” i cell A1 i det första kalkylbladet och sparas 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-mallfil “Sample.xlsx”, infogar “Hello World!” i cell A1 i det första kalkylbladet och sparas 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(); |