背景色

シートのDefaultStyleプロパティにBackColorを指定することで、シート全体の背景色を変更することができます。
背景色の変更はセル単位、列単位、行単位など様々な単位で設定することが可能です。

このサンプルではドロップダウンリストで選択した色をセル全体の背景色として設定しています。
背景色
 ID氏名カナ生年月日性別血液型部署入社日メールアドレス
11001亀甲 滋万キコウ シゲマ1950/02/04A人事部1972/04/01sigema_kikou@abc.co.jp
21002寒田 希世カンダ キヨ1959/06/28B人事部1981/04/01kiyo_kanda@bbb.or.jp
31003小和瀬 澄オワセ キヨ1969/03/06A人事部1991/04/01kiyo_owase@aaa.co.jp
41004宇夫 早余子ウブ サヨコ1976/07/28O人事部1998/04/01sayoko_ubu@bbb.or.jp
51005宇田津 聖智ウダツ キヨトモ1965/09/04A営業部1987/04/01kiyotomo_udatu@abc.co.jp
61006茨城 昭児イバラキ ショウジ1963/04/28O営業部1985/04/01shouzi_ibaraki@xyz.ne.jp
71007石ヶ休 椎茄イシガキュウ シイナ1953/02/21O営業部1975/04/01siina_isigagyuu@abc.co.jp
81008赤司 恵治郎アカツカサ ケイジロウ1968/08/02O経理部1990/04/01keizirou_akatukasa@abc.co.jp
91009小橋 仰一オハシ ギョウイチ1972/03/02B経理部1994/04/01gyouiti_ohasi@abc.co.jp
101010一重 公大イチジュウ コウダイ1964/04/19B経理部1986/04/01koudai_itizyuu@xyz.ne.jp
111011稲並 勝五郎イナミ ショウゴロウ1962/02/18A営業部1984/04/01shougorou_inami@bbb.or.jp
121012穎原 紀代一エイハラ キヨカズ1965/02/13O営業部1987/04/01kiyokazu_eihara@bbb.or.jp

ソースコード

別ウィンドウで表示
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;

public partial class backcolor : System.Web.UI.Page
{
    private  System.Drawing.Color DEF_COL = new System.Drawing.Color();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;

        // データ連結
        DataSet ds = new DataSet();
        ds.ReadXml(MapPath("../App_Data/data.xml"));
        FpSpread1.DataSource = ds;        
        
        // SPREAD初期化
        InitSpread(FpSpread1.Sheets[0]);

        // クライアント側スクリプトの設定
        string clientScript = "<script language=\"JavaScript\">";
        clientScript += "function SetBackColor(bcolor)";
        clientScript += "{";
        clientScript += "var spread = document.getElementById(\"" + FpSpread1.ClientID + "\");";
        clientScript += "spread.CallBack(\"SetBackColor.\"+bcolor);";
        clientScript += "}";
        clientScript += "</script>";

        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "backcolorScript", clientScript, false);
    }

    private void InitSpread(FarPoint.Web.Spread.SheetView sheet)
    {
        // SPREAD設定
        FpSpread1.CommandBar.Visible = false;
        FpSpread1.CssClass = "spreadStyle";
        FpSpread1.UseClipboard = false;

        // フォントサイズの設定
        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.PageSize = sheet.RowCount;

        // 列幅の設定
        sheet.Columns[0].Width = 36;
        sheet.Columns[1].Width = 88;
        sheet.Columns[2].Width = 91;
        sheet.Columns[3].Width = 80;
        sheet.Columns[4].Width = 36;
        sheet.Columns[5].Width = 46;
        sheet.Columns[6].Width = 49;
        sheet.Columns[7].Width = 80;
        sheet.Columns[8].Width = 181;

        // 縦方向の揃え位置を中央に設定
        sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;

        // 初期値保存
        DEF_COL = FpSpread1.ActiveSheetView.DefaultStyle.BackColor;
    }

    protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
    {
        if (e.CommandName.StartsWith("SetBackColor"))
        {
            string[] strCom = e.CommandName.Split('.');

            if (strCom[1] == "")
            {
                FpSpread1.ActiveSheetView.DefaultStyle.BackColor = DEF_COL;
            }
            else
            {
                System.Drawing.Color bc = System.Drawing.Color.FromName(strCom[1]);
                FpSpread1.ActiveSheetView.DefaultStyle.BackColor = bc;
            }
        }
    }
}

Partial Public Class backcolor
    Inherits System.Web.UI.Page

    Private DEF_COL As New System.Drawing.Color()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            Return
        End If

        ' データ連結
        Dim ds As New System.Data.DataSet()
        ds.ReadXml(MapPath("../App_Data/data.xml"))
        FpSpread1.DataSource = ds

        ' SPREAD初期化
        InitSpread(FpSpread1.Sheets(0))

        ' クライアント側スクリプトの設定
        Dim clientScript As String = "<script language=""JavaScript"">"
        clientScript += "function SetBackColor(bcolor)"
        clientScript += "{"
        clientScript += "var spread = document.getElementById(""" + FpSpread1.ClientID & """);"
        clientScript += "spread.CallBack(""SetBackColor.""+bcolor);"
        clientScript += "}"
        clientScript += "</script>"

        ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "backcolorScript", clientScript, False)
    End Sub

    Private Sub InitSpread(ByVal sheet As FarPoint.Web.Spread.SheetView)
        ' SPREAD設定
        FpSpread1.CommandBar.Visible = False
        FpSpread1.CssClass = "spreadStyle"
        FpSpread1.UseClipboard = False

        ' フォントサイズの設定
        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.PageSize = sheet.RowCount

        ' 列幅の設定
        sheet.Columns(0).Width = 36
        sheet.Columns(1).Width = 88
        sheet.Columns(2).Width = 91
        sheet.Columns(3).Width = 80
        sheet.Columns(4).Width = 36
        sheet.Columns(5).Width = 46
        sheet.Columns(6).Width = 49
        sheet.Columns(7).Width = 80
        sheet.Columns(8).Width = 181

        ' 縦方向の揃え位置を中央に設定
        sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle

        ' 初期値保存
        DEF_COL = FpSpread1.ActiveSheetView.DefaultStyle.BackColor
    End Sub

    Protected Sub FpSpread1_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
        If e.CommandName.StartsWith("SetBackColor") Then
            Dim strCom As String() = e.CommandName.Split("."c)

            If strCom(1) = "" Then
                FpSpread1.ActiveSheetView.DefaultStyle.BackColor = DEF_COL
            Else
                Dim bc As System.Drawing.Color = System.Drawing.Color.FromName(strCom(1))
                FpSpread1.ActiveSheetView.DefaultStyle.BackColor = bc
            End If
        End If
    End Sub
End Class
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true" 
         Inherits="backcolor" CodeFile="backcolor.aspx.cs" %>

<%@ 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">
    <asp:Label ID="Label1" runat="server" Text="背景色"></asp:Label>
    <asp:DropDownList ID="DDLbc" runat="server" onchange="SetBackColor(this[this.selectedIndex].text);" >
        <asp:ListItem value="">初期値</asp:ListItem>
        <asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: black" value="Black">Black</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: gray" value="Gray">Gray</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: darkgray" value="DarkGray">DarkGray</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: lightgrey" value="LightGray">LightGray</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: white" value="White">White</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: aquamarine" value="Aquamarine">Aquamarine</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: blue" value="Blue">Blue</asp:ListItem>
        <asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: navy" value="Navy">Navy</asp:ListItem>
        <asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: purple" value="Purple">Purple</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: deeppink" value="DeepPink">DeepPink</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: violet" value="Violet">Violet</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: pink" value="Pink">Pink</asp:ListItem>
        <asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: darkgreen" value="DarkGreen">DarkGreen
        </asp:ListItem>
        <asp:ListItem style="COLOR: #ffffff; BACKGROUND-COLOR: green" value="Green">Green</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: yellowgreen" value="YellowGreen">YellowGreen</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: yellow" value="Yellow">Yellow</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: orange" value="Orange">Orange</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: red" value="Red">Red</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: brown" value="Brown">Brown</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: burlywood" value="BurlyWood">BurlyWood</asp:ListItem>
        <asp:ListItem style="BACKGROUND-COLOR: beige" value="Beige">Beige</asp:ListItem>   
    </asp:DropDownList>
    <farpoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
        BorderWidth="1px" onbuttoncommand="FpSpread1_ButtonCommand">
        <CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
            ButtonShadowColor="ControlDark" />
        <Sheets>
            <farpoint:SheetView SheetName="Sheet1">
            </farpoint:SheetView>
        </Sheets>
    </farpoint:FpSpread>
</asp:Content>