Excelフィルタリング
SPREADでは、従来の単一データに絞り込むフィルタリングの他、Excel2010スタイルのフィルタリングが可能です。
フィルタしたい文字の検索、列の一意の値を含むチェックボックス、条件フィルタが利用でき、複数項目の絞り込みが簡単に実現できます。
| 連番 | | | | |
1 | 1000 | 長岡 文音 | 女 | 1980/07/09 | 32 |
2 | 1001 | 住田 晶子 | 女 | 1992/10/20 | 20 |
3 | 1002 | 西沢 有希 | 女 | 1961/04/15 | 51 |
4 | 1003 | 石渡 実緒 | 女 | 1954/05/24 | 58 |
5 | 1004 | 大林 芳雄 | 男 | 1981/06/29 | 31 |
6 | 1005 | 花井 理津子 | 女 | 1984/10/16 | 28 |
7 | 1006 | 永田 浩司 | 男 | 1968/01/22 | 44 |
8 | 1007 | 古山 春菜 | 女 | 1976/03/15 | 36 |
9 | 1008 | 水島 幸真 | 男 | 1959/04/06 | 53 |
10 | 1009 | 浜田 雅典 | 男 | 1962/03/30 | 50 |
|
|
ソースコード
別ウィンドウで表示
using System;
using System.Web.UI.WebControls;
public partial class filtering_enhancedfilter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return;
}
// SPREADの設定
InitSpread(FpSpread1);
// シート設定
InitSpreadStyles(FpSpread1.Sheets[0]);
}
private void InitSpread(FarPoint.Web.Spread.FpSpread spread)
{
//データ連結
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(MapPath("../App_Data/dataexcelfilter.xml"));
spread.DataSource = ds;
spread.CssClass = "spreadStyle";
spread.UseClipboard = false;
}
private void InitSpreadStyles(FarPoint.Web.Spread.SheetView sheet)
{
// フォントサイズの設定
sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%");
sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%");
// 列幅の設定
sheet.Columns[0].Width = 50;
sheet.Columns[1].Width = 120;
sheet.Columns[2].Width = 80;
sheet.Columns[3].Width = 100;
sheet.Columns[4].Width = 80;
// 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
// 背景色の設定
for (int i = 0; i < sheet.RowCount; i++)
{
if (i % 5 == 0)
{
sheet.Rows[i].BackColor = System.Drawing.Color.Azure;
}
else if (i % 5 == 1)
{
sheet.Rows[i].BackColor = System.Drawing.Color.Beige;
}
else if (i % 5 == 2)
{
sheet.Rows[i].BackColor = System.Drawing.Color.LavenderBlush;
}
else if (i % 5 == 3)
{
sheet.Rows[i].BackColor = System.Drawing.Color.Silver;
}
else if (i % 5 == 4)
{
sheet.Rows[i].BackColor = System.Drawing.Color.PaleVioletRed;
}
}
// フィルタリングの設定
sheet.AutoFilterMode = FarPoint.Web.Spread.AutoFilterMode.Enhanced;
FarPoint.Web.Spread.IRowFilter rowFilter = new FarPoint.Web.Spread.HideRowFilter(sheet);
FarPoint.Web.Spread.FilterColumnDefinition fd1 = new FarPoint.Web.Spread.FilterColumnDefinition(1, FarPoint.Web.Spread.FilterListBehavior.Default);
FarPoint.Web.Spread.FilterColumnDefinition fd2 = new FarPoint.Web.Spread.FilterColumnDefinition(2, FarPoint.Web.Spread.FilterListBehavior.Default);
FarPoint.Web.Spread.FilterColumnDefinition fd3 = new FarPoint.Web.Spread.FilterColumnDefinition(3, FarPoint.Web.Spread.FilterListBehavior.Default);
FarPoint.Web.Spread.FilterColumnDefinition fd4 = new FarPoint.Web.Spread.FilterColumnDefinition(4, FarPoint.Web.Spread.FilterListBehavior.Default);
rowFilter.ColumnDefinitions.Add(fd1);
rowFilter.ColumnDefinitions.Add(fd2);
rowFilter.ColumnDefinitions.Add(fd3);
rowFilter.ColumnDefinitions.Add(fd4);
sheet.RowFilter = rowFilter;
}
}
|
Partial Class filtering_enhancedfilter
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Return
End If
' SPREADの設定
InitSpread(FpSpread1)
' シート設定
InitSpreadStyles(FpSpread1.Sheets(0))
End Sub
Private Sub InitSpread(ByVal spread As FarPoint.Web.Spread.FpSpread)
'データ連結
Dim ds As New System.Data.DataSet()
ds.ReadXml(MapPath("../App_Data/dataexcelfilter.xml"))
spread.DataSource = ds
spread.CssClass = "spreadStyle"
spread.UseClipboard = False
End Sub
Private Sub InitSpreadStyles(ByVal sheet As FarPoint.Web.Spread.SheetView)
' フォントサイズの設定
sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%")
sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%")
' 列幅の設定
sheet.Columns(0).Width = 50
sheet.Columns(1).Width = 120
sheet.Columns(2).Width = 80
sheet.Columns(3).Width = 100
sheet.Columns(4).Width = 80
' 縦方向の揃え位置を中央に設定
sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle
' 背景色の設定
For i As Integer = 0 To sheet.RowCount - 1
If i Mod 5 = 0 Then
sheet.Rows(i).BackColor = Drawing.Color.Azure
ElseIf i Mod 5 = 1 Then
sheet.Rows(i).BackColor = Drawing.Color.Beige
ElseIf i Mod 5 = 2 Then
sheet.Rows(i).BackColor = Drawing.Color.LavenderBlush
ElseIf i Mod 5 = 3 Then
sheet.Rows(i).BackColor = Drawing.Color.Silver
ElseIf i Mod 5 = 4 Then
sheet.Rows(i).BackColor = Drawing.Color.PaleVioletRed
End If
Next
' フィルタリングの設定
sheet.AutoFilterMode = FarPoint.Web.Spread.AutoFilterMode.Enhanced
Dim rowFilter As FarPoint.Web.Spread.IRowFilter = New FarPoint.Web.Spread.HideRowFilter(sheet)
Dim fd1 As New FarPoint.Web.Spread.FilterColumnDefinition(1, FarPoint.Web.Spread.FilterListBehavior.Default)
Dim fd2 As New FarPoint.Web.Spread.FilterColumnDefinition(2, FarPoint.Web.Spread.FilterListBehavior.Default)
Dim fd3 As New FarPoint.Web.Spread.FilterColumnDefinition(3, FarPoint.Web.Spread.FilterListBehavior.Default)
Dim fd4 As New FarPoint.Web.Spread.FilterColumnDefinition(4, FarPoint.Web.Spread.FilterListBehavior.Default)
rowFilter.ColumnDefinitions.Add(fd1)
rowFilter.ColumnDefinitions.Add(fd2)
rowFilter.ColumnDefinitions.Add(fd3)
rowFilter.ColumnDefinitions.Add(fd4)
sheet.RowFilter = rowFilter
End Sub
End Class
|
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="enhancedfilter.aspx.cs" Inherits="filtering_enhancedfilter" %>
<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder1" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
BorderWidth="1px">
<CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
ButtonShadowColor="ControlDark">
</CommandBar>
<Sheets>
<FarPoint:SheetView SheetName="Sheet1">
</FarPoint:SheetView>
</Sheets>
</FarPoint:FpSpread>
</asp:Content>
|