|
条件付き書式
ある条件に該当するセルに対して特別なスタイルを設定することができます。
Ver 5.0Jまでの背景色や文字の色、フォントの他、Ver 7.0Jからはセル内に入力されている数値を見比べる際に役立つ「データバー」、
分布状況を把握するのに役立つ「カラースケール」、所属するランクを見比べる際に役立つ「アイコンセット」が利用できます。
| 氏名 | 国語 | 数学 | 理科 | 社会 | 英語 |
1 | 亀甲 滋万 | | | | | |
2 | 寒田 希世 | | | | | |
3 | 小和瀬 澄 | | | | | |
4 | 宇夫 早余子 | | | | | |
5 | 宇田津 聖智 | | | | | |
6 | 茨城 昭児 | | | | | |
7 | 石ヶ休 椎茄 | | | | | |
8 | 赤司 恵治郎 | | | | | |
9 | 平均 | | | | | |
|
|
ソースコード
別ウィンドウで表示
using System;
using System.Web.UI.WebControls;
public partial class style_conditionalformat7 : 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/dataconditionalformat.xml"));
FpSpread1.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.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
// 列幅の設定
sheet.Columns[0].Width = 120;
sheet.Columns[1].Width = 80;
sheet.Columns[2].Width = 80;
sheet.Columns[3].Width = 80;
sheet.Columns[4].Width = 80;
sheet.Columns[5].Width = 80;
// 行の追加
sheet.AddRows(sheet.RowCount, 1);
sheet.Cells[sheet.RowCount - 1, 0].Value = "平均";
sheet.Rows[sheet.RowCount - 1].BackColor = System.Drawing.Color.Khaki;
// 数式の設定
for (int i = 1; i < sheet.ColumnCount; i++)
{
string col = Convert.ToString((char)(65 + i));
sheet.Cells[sheet.RowCount - 1, i].Formula = "AVERAGE(" + col + "1:" + col + Convert.ToString(sheet.RowCount - 1) + ")";
}
FarPoint.Web.Spread.ConditionalFormatting cf = new FarPoint.Web.Spread.ConditionalFormatting(new FarPoint.Web.Spread.Model.CellRange(0, 1, sheet.RowCount - 1, sheet.ColumnCount));
FarPoint.Web.Spread.DatabarConditionalFormattingRule rule = new FarPoint.Web.Spread.DatabarConditionalFormattingRule();
rule.BorderColor = System.Drawing.Color.Silver;
rule.ShowBorder = true;
rule.Gradient = true;
rule.Minimum = new FarPoint.Web.Spread.ConditionalFormattingValue(0, FarPoint.Web.Spread.ConditionalFormattingValueType.Number);
rule.Maximum = new FarPoint.Web.Spread.ConditionalFormattingValue(100, FarPoint.Web.Spread.ConditionalFormattingValueType.Max);
cf.Add(rule);
sheet.ConditionalFormatting.Add(cf);
FarPoint.Web.Spread.ConditionalFormatting cf1 = new FarPoint.Web.Spread.ConditionalFormatting(new FarPoint.Web.Spread.Model.CellRange(sheet.RowCount - 1, 1, 1, sheet.ColumnCount));
FarPoint.Web.Spread.IconSetConditionalFormattingRule rule1 = new FarPoint.Web.Spread.IconSetConditionalFormattingRule(FarPoint.Web.Spread.ConditionalFormattingIconSetStyle.ThreeFlags);
cf1.Add(rule1);
sheet.ConditionalFormatting.Add(cf1);
}
}
|
Partial Class style_conditionalformat7
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/dataconditionalformat.xml"))
FpSpread1.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.DefaultStyle.VerticalAlign = VerticalAlign.Middle
' 列幅の設定
sheet.Columns(0).Width = 120
sheet.Columns(1).Width = 80
sheet.Columns(2).Width = 80
sheet.Columns(3).Width = 80
sheet.Columns(4).Width = 80
sheet.Columns(5).Width = 80
' 行の追加
sheet.AddRows(sheet.RowCount, 1)
sheet.Cells(sheet.RowCount - 1, 0).Value = "平均"
sheet.Rows(sheet.RowCount - 1).BackColor = System.Drawing.Color.Khaki
' 数式の設定
For i As Integer = 1 To sheet.ColumnCount - 1
Dim col As String = Convert.ToString(ChrW(65 + i))
sheet.Cells(sheet.RowCount - 1, i).Formula = "AVERAGE(" & col & "1:" & col & Convert.ToString(sheet.RowCount - 1) & ")"
Next
Dim cf As New FarPoint.Web.Spread.ConditionalFormatting(New FarPoint.Web.Spread.Model.CellRange(0, 1, sheet.RowCount - 1, sheet.ColumnCount))
Dim rule As New FarPoint.Web.Spread.DatabarConditionalFormattingRule()
rule.BorderColor = System.Drawing.Color.Silver
rule.ShowBorder = True
rule.Gradient = True
rule.Minimum = New FarPoint.Web.Spread.ConditionalFormattingValue(0, FarPoint.Web.Spread.ConditionalFormattingValueType.Number)
rule.Maximum = New FarPoint.Web.Spread.ConditionalFormattingValue(100, FarPoint.Web.Spread.ConditionalFormattingValueType.Max)
cf.Add(rule)
sheet.ConditionalFormatting.Add(cf)
Dim cf1 As New FarPoint.Web.Spread.ConditionalFormatting(New FarPoint.Web.Spread.Model.CellRange(sheet.RowCount - 1, 1, 1, sheet.ColumnCount))
Dim rule1 As New FarPoint.Web.Spread.IconSetConditionalFormattingRule(FarPoint.Web.Spread.ConditionalFormattingIconSetStyle.ThreeFlags)
cf1.Add(rule1)
sheet.ConditionalFormatting.Add(cf1)
End Sub
End Class
|
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="conditionalformat7.aspx.cs" Inherits="style_conditionalformat7" %>
<%@ 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>
|
|
|
|