ナビゲーション リンクのスキップ
 新機能 の展開 新機能
 InputMan連携 の展開 InputMan連携
 マルチタッチ機能 の展開 マルチタッチ機能
 セル、行、列、ヘッダ の展開 セル、行、列、ヘッダ
 シート の展開 シート
 スタイル の展開 スタイル
 選択 の縮小 選択
 セル型 の展開 セル型
 編集 の展開 編集
 ソート の展開 ソート
 フィルタリング の展開 フィルタリング
 グループ化 の展開 グループ化
 ページング の展開 ページング
 スクロール の展開 スクロール
 データ連結 の展開 データ連結
 階層表示 の展開 階層表示
 コマンドバー の展開 コマンドバー
 チャート の展開 チャート
 数式 の展開 数式
 インポート/エクスポート の展開 インポート/エクスポート
 クライアント側スクリプト の展開 クライアント側スクリプト

選択のスタイル

選択セルの外観を確認することができます。 セルの背景色、アクティブセルの周囲に罫線を設定、罫線の色、罫線のスタイルを変更することができます。 選択されたセルの背景色を選択色で塗りつぶすだけではなく、選択されたセルの背景色と選択色を 合成させる、または選択色を表示しないことも可能です。

アクティブセルを罫線で囲む(ShowFocusRectangle = true)設定をした場合、アクティブセルの背景色は変更されず、アクティブセル以外の選択範囲の背景色が変更されます。

 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 selectionstyle : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        string js = "var spid='" + FpSpread1.ClientID + "';";
        ClientScript.RegisterStartupScript(this.GetType(), "onStartUpScript", js, true);

        if (IsPostBack) return;

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

    private void InitSpread(FarPoint.Web.Spread.SheetView sheet)
    {
        int i;
        Random r = new Random(DateTime.Now.Hour * DateTime.Now.Minute * DateTime.Now.Second + DateTime.Now.Millisecond);

        // 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;

        // 背景色の設定
        for (i = 0; i < FpSpread1.ActiveSheetView.RowCount; i++)
        {
            FpSpread1.ActiveSheetView.Cells[i, 3].BackColor = System.Drawing.Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
        }

        // 縦方向の揃え位置を中央に設定
        sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
    }
   
    protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
    {
        if (e.CommandName.StartsWith("SetSelectionBackColor"))
        {
            string[] strCom = e.CommandName.Split('.');

            System.Drawing.Color bc = System.Drawing.ColorTranslator.FromHtml(strCom[1]);
            FpSpread1.ActiveSheetView.SelectionBackColor = bc;
        }
        else if (e.CommandName.StartsWith("SetSBackColorStyle"))
        {
            string[] strCom = e.CommandName.Split('.');

            if (strCom[1] == "None")
            {
                FpSpread1.ActiveSheetView.SelectionBackColorStyle = FarPoint.Web.Spread.SelectionBackColorStyles.None;
            }
            else if (strCom[1] == "SelectionBackColor")
            {
                FpSpread1.ActiveSheetView.SelectionBackColorStyle = FarPoint.Web.Spread.SelectionBackColorStyles.SelectionBackColor;
            }
            else if (strCom[1] == "SemiTransparentSelectionBackColor")
            {
                FpSpread1.ActiveSheetView.SelectionBackColorStyle = FarPoint.Web.Spread.SelectionBackColorStyles.SemiTransparentSelectionBackColor;
            }
        }
        else if (e.CommandName.StartsWith("ShowFocusRectangle"))
        {
            string[] strCom = e.CommandName.Split('.');

            FpSpread1.ShowFocusRectangle = Convert.ToBoolean(strCom[1]);
        }
        else if (e.CommandName.StartsWith("SetBorderColor"))
        {
            string[] strCom = e.CommandName.Split('.');

            System.Drawing.Color bc = System.Drawing.ColorTranslator.FromHtml(strCom[1]);
            FpSpread1.FocusRectangleBorderColor = bc;
        }
        else if (e.CommandName.StartsWith("SetBorderStyle"))
        {
            string[] strCom = e.CommandName.Split('.');

            if (strCom[1] == "Solid")
            {
                FpSpread1.FocusRectangleBorderStyle = FarPoint.Web.Spread.FocusBorderStyle.Solid;
            }
            else if (strCom[1] == "Dotted")
            {
                FpSpread1.FocusRectangleBorderStyle = FarPoint.Web.Spread.FocusBorderStyle.Dotted;
            }
            else if (strCom[1] == "Dashed")
            {
                FpSpread1.FocusRectangleBorderStyle = FarPoint.Web.Spread.FocusBorderStyle.Dashed;
            }
        }
    }
}

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim js As String = "var spid='" + FpSpread1.ClientID & "';"
        ClientScript.RegisterStartupScript(Me.GetType(), "onStartUpScript", js, True)

        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))
    End Sub

    Private Sub InitSpread(ByVal sheet As FarPoint.Web.Spread.SheetView)
        Dim i As Integer
        Dim r As New Random(DateTime.Now.Hour * DateTime.Now.Minute * DateTime.Now.Second + DateTime.Now.Millisecond)

        ' 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

        ' 背景色の設定
        For i = 0 To FpSpread1.ActiveSheetView.RowCount - 1
            FpSpread1.ActiveSheetView.Cells(i, 3).BackColor = System.Drawing.Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255))
        Next

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

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

            Dim bc As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml(strCom(1))
            FpSpread1.ActiveSheetView.SelectionBackColor = bc
        ElseIf e.CommandName.StartsWith("SetSBackColorStyle") Then
            Dim strCom As String() = e.CommandName.Split("."c)

            If strCom(1) = "None" Then
                FpSpread1.ActiveSheetView.SelectionBackColorStyle = FarPoint.Web.Spread.SelectionBackColorStyles.None
            ElseIf strCom(1) = "SelectionBackColor" Then
                FpSpread1.ActiveSheetView.SelectionBackColorStyle = FarPoint.Web.Spread.SelectionBackColorStyles.SelectionBackColor
            ElseIf strCom(1) = "SemiTransparentSelectionBackColor" Then
                FpSpread1.ActiveSheetView.SelectionBackColorStyle = FarPoint.Web.Spread.SelectionBackColorStyles.SemiTransparentSelectionBackColor
            End If
        ElseIf e.CommandName.StartsWith("ShowFocusRectangle") Then
            Dim strCom As String() = e.CommandName.Split("."c)

            FpSpread1.ShowFocusRectangle = Convert.ToBoolean(strCom(1))
        ElseIf e.CommandName.StartsWith("SetBorderColor") Then
            Dim strCom As String() = e.CommandName.Split("."c)

            Dim bc As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml(strCom(1))
            FpSpread1.FocusRectangleBorderColor = bc
        ElseIf e.CommandName.StartsWith("SetBorderStyle") Then
            Dim strCom As String() = e.CommandName.Split("."c)

            If strCom(1) = "Solid" Then
                FpSpread1.FocusRectangleBorderStyle = FarPoint.Web.Spread.FocusBorderStyle.Solid
            ElseIf strCom(1) = "Dotted" Then
                FpSpread1.FocusRectangleBorderStyle = FarPoint.Web.Spread.FocusBorderStyle.Dotted
            ElseIf strCom(1) = "Dashed" Then
                FpSpread1.FocusRectangleBorderStyle = FarPoint.Web.Spread.FocusBorderStyle.Dashed
            End If
        End If
    End Sub
End Class
<%@ Page MasterPageFile="~/MasterPage.master" Language="c#" AutoEventWireup="true" 
         Inherits="selectionstyle" CodeFile="selectionstyle.aspx.cs" %>

<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder1" Runat="Server">
    <script type="text/javascript">
        function SetSelectionBackColor(color) {
            var spread = document.getElementById(spid);
            spread.CallBack("SetSelectionBackColor." + color);
        }
        function SetSBackColorStyle(sbstyle) {
            var spread = document.getElementById(spid);
            spread.CallBack("SetSBackColorStyle." + sbstyle);
        }
        function ShowFocusRectangle(val) {
            var spread = document.getElementById(spid);
            spread.CallBack("ShowFocusRectangle." + val);
        }
        function SetBorderColor(bdcolor) {
            var spread = document.getElementById(spid);
            spread.CallBack("SetBorderColor." + bdcolor);
        }
        function SetBorderStyle(bstyle) {
            var spread = document.getElementById(spid);
            spread.CallBack("SetBorderStyle." + bstyle);
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <select style="width: 85px" tabindex="-1" onchange="SetSelectionBackColor(this[this.selectedIndex].value);this.selectedIndex=0;">
	    <option value="">選択色</option>
	    <option style="color: #ffffff; background-color: black" value="#000000">Black</option>
	    <option style="background-color: #808080" value="#808080">Gray</option>
	    <option style="background-color: #A9A9A9" value="#A9A9A9">DarkGray</option>
	    <option style="background-color: #D3D3D3" value="#D3D3D3">LightGray</option>
	    <option style="background-color: #FFFFFF" value="#FFFFFF">White</option>
	    <option style="background-color: #7FFFD4" value="#7FFFD4">Aquamarine</option>
	    <option style="background-color: #0000FF" value="#0000FF">Blue</option>
	    <option style="color: #ffffff; background-color: #000080" value="#000080">Navy</option>
	    <option style="color: #ffffff; background-color: #800080" value="#800080">Purple</option>
	    <option style="background-color: #FF1493" value="#FF1493">DeepPink</option>
	    <option style="background-color: #EE82EE" value="#EE82EE">Violet</option>
	    <option style="background-color: #FFC0CB" value="#FFC0CB">Pink</option>
	    <option style="color: #ffffff; background-color: #006400" value="#006400">DarkGreen</option>
	    <option style="color: #ffffff; background-color: #008000" value="#008000">Green</option>
	    <option style="background-color: #9ACD32" value="#9ACD32">YellowGreen</option>
	    <option style="background-color: #FFFF00" value="#FFFF00">Yellow</option>
	    <option style="background-color: #FFA500" value="#FFA500">Orange</option>
	    <option style="background-color: #FF0000" value="#FF0000">Red</option>
	    <option style="background-color: #A52A2A" value="#A52A2A">Brown</option>
	    <option style="background-color: #DEB887" value="#DEB887">BurlyWood</option>
	    <option style="background-color: #F5F5DC" value="#F5F5DC">Beige</option>
    </select>
	<select style="width: 140px" tabindex="-1" onchange="SetSBackColorStyle(this[this.selectedIndex].value);">
		<option value="">選択色のスタイル</option>
		<option value="None">選択色を表示しない</option>
        <option value="SelectionBackColor">背景色を塗りつぶす</option>
        <option value="SemiTransparentSelectionBackColor">選択色を透過させる</option>
	</select>
    <br />
    <asp:CheckBox ID="chkRectangle" runat="server" 
            Text="アクティブセルを罫線で囲む" onclick="ShowFocusRectangle(this.checked);" />
    <select style="width: 100px" tabindex="-1" onchange="SetBorderColor(this[this.selectedIndex].value);this.selectedIndex=0;">
	    <option value="">選択枠の色</option>
	    <option style="color: #ffffff; background-color: black" value="#000000">Black</option>
	    <option style="background-color: #808080" value="#808080">Gray</option>
	    <option style="background-color: #A9A9A9" value="#A9A9A9">DarkGray</option>
	    <option style="background-color: #D3D3D3" value="#D3D3D3">LightGray</option>
	    <option style="background-color: #FFFFFF" value="#FFFFFF">White</option>
	    <option style="background-color: #7FFFD4" value="#7FFFD4">Aquamarine</option>
	    <option style="background-color: #0000FF" value="#0000FF">Blue</option>
	    <option style="color: #ffffff; background-color: #000080" value="#000080">Navy</option>
	    <option style="color: #ffffff; background-color: #800080" value="#800080">Purple</option>
	    <option style="background-color: #FF1493" value="#FF1493">DeepPink</option>
	    <option style="background-color: #EE82EE" value="#EE82EE">Violet</option>
	    <option style="background-color: #FFC0CB" value="#FFC0CB">Pink</option>
	    <option style="color: #ffffff; background-color: #006400" value="#006400">DarkGreen</option>
	    <option style="color: #ffffff; background-color: #008000" value="#008000">Green</option>
	    <option style="background-color: #9ACD32" value="#9ACD32">YellowGreen</option>
	    <option style="background-color: #FFFF00" value="#FFFF00">Yellow</option>
	    <option style="background-color: #FFA500" value="#FFA500">Orange</option>
	    <option style="background-color: #FF0000" value="#FF0000">Red</option>
	    <option style="background-color: #A52A2A" value="#A52A2A">Brown</option>
	    <option style="background-color: #DEB887" value="#DEB887">BurlyWood</option>
	    <option style="background-color: #F5F5DC" value="#F5F5DC">Beige</option>
    </select>
    <select style="width: 120px" tabindex="-1" onchange="SetBorderStyle(this[this.selectedIndex].value);this.selectedIndex=0;">
		<option value="">選択枠のスタイル</option>
		<option value="Solid">実線</option>
        <option value="Dotted">点線</option>
        <option value="Dashed">破線</option>
	</select>
    <FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
        BorderWidth="1px" onbuttoncommand="FpSpread1_ButtonCommand">
        <CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
            ButtonShadowColor="ControlDark">
        </CommandBar>
        <Sheets>
            <FarPoint:SheetView SheetName="Sheet1">
            </FarPoint:SheetView>
        </Sheets>
    </FarPoint:FpSpread>
</asp:Content>