
5 changed files with 191 additions and 7 deletions
-
21examples/NPOI.XSSF.Examples.2012.sln
-
67examples/xssf/LineChart/LineChart.csproj
-
67examples/xssf/LineChart/Program.cs
-
36examples/xssf/LineChart/Properties/AssemblyInfo.cs
-
7examples/xssf/ScatterChart/Program.cs
@ -0,0 +1,67 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}</ProjectGuid> |
|||
<OutputType>Exe</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>LineChart</RootNamespace> |
|||
<AssemblyName>LineChart</AssemblyName> |
|||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<PlatformTarget>AnyCPU</PlatformTarget> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<PlatformTarget>AnyCPU</PlatformTarget> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="NPOI"> |
|||
<HintPath>..\..\..\solution\Lib\NPOI.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="NPOI.OOXML"> |
|||
<HintPath>..\..\..\solution\Lib\NPOI.OOXML.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="NPOI.OpenXml4Net"> |
|||
<HintPath>..\..\..\solution\Lib\NPOI.OpenXml4Net.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="NPOI.OpenXmlFormats"> |
|||
<HintPath>..\..\..\solution\Lib\NPOI.OpenXmlFormats.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Data.DataSetExtensions" /> |
|||
<Reference Include="Microsoft.CSharp" /> |
|||
<Reference Include="System.Data" /> |
|||
<Reference Include="System.Xml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="Program.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
@ -0,0 +1,67 @@ |
|||
using NPOI.SS.UserModel; |
|||
using NPOI.SS.UserModel.Charts; |
|||
using NPOI.SS.Util; |
|||
using NPOI.XSSF.UserModel; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace LineChart |
|||
{ |
|||
class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
{ |
|||
IWorkbook wb = new XSSFWorkbook(); |
|||
ISheet sheet = wb.CreateSheet("linechart"); |
|||
int NUM_OF_ROWS = 3; |
|||
int NUM_OF_COLUMNS = 10; |
|||
|
|||
// Create a row and put some cells in it. Rows are 0 based.
|
|||
IRow row; |
|||
ICell cell; |
|||
for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) |
|||
{ |
|||
row = sheet.CreateRow((short)rowIndex); |
|||
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) |
|||
{ |
|||
cell = row.CreateCell((short)colIndex); |
|||
cell.SetCellValue(colIndex * (rowIndex + 1)); |
|||
} |
|||
} |
|||
|
|||
IDrawing drawing = sheet.CreateDrawingPatriarch(); |
|||
IClientAnchor anchor = drawing.CreateAnchor(0, 0, 0, 0, 0, 5, 10, 15); |
|||
|
|||
IChart chart = drawing.CreateChart(anchor); |
|||
IChartLegend legend = chart.GetOrCreateLegend(); |
|||
legend.Position = LegendPosition.TopRight; |
|||
|
|||
ILineChartData<double, double> data = chart.GetChartDataFactory().CreateLineChartData<double, double>(); |
|||
|
|||
// Use a category axis for the bottom axis.
|
|||
IChartAxis bottomAxis = chart.GetChartAxisFactory().CreateCategoryAxis(AxisPosition.Bottom); |
|||
IValueAxis leftAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Left); |
|||
leftAxis.SetCrosses(AxisCrosses.AutoZero); |
|||
|
|||
IChartDataSource<double> xs = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1)); |
|||
IChartDataSource<double> ys1 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1)); |
|||
IChartDataSource<double> ys2 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1)); |
|||
|
|||
|
|||
var s1 = data.AddSerie(xs, ys1); |
|||
s1.SetTitle("title1"); |
|||
var s2 = data.AddSerie(xs, ys2); |
|||
s2.SetTitle("title2"); |
|||
|
|||
chart.Plot(data, bottomAxis, leftAxis); |
|||
|
|||
using (FileStream fs =File.Create("test.xlsx")) |
|||
{ |
|||
wb.Write(fs); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("LineChart")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("LineChart")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("fe9a40ad-670a-4813-9b3a-0791300c2f9f")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Write
Preview
Loading…
Cancel
Save
Reference in new issue