// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); object[,] data = new object[,]{ {"名前", "地域", "生年月日", "血液型", "体重", "身長"}, {"伊達", "西地区", new DateTime(1968, 6, 8), "A", 67, 165}, {"上杉", "北地区", new DateTime(1972, 7, 3), "B", 62, 134}, {"最上", "西地区", new DateTime(1964, 3, 2), "O", 72, 180}, {"片倉", "南地区", new DateTime(1972, 8, 8), "A", 66, 163}, {"田村", "東地区", new DateTime(1986, 2, 2), "A", 76, 176}, {"津軽", "北地区", new DateTime(1993, 2, 15), "AB", 68, 145} }; IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1:F7"].Value = data; worksheet.Range["A:F"].ColumnWidth = 15; worksheet.Range["F2"].Font.Color = Color.Red; worksheet.Range["F3"].Font.Color = Color.Gainsboro; worksheet.Range["F4"].Font.Color = Color.Green; worksheet.Range["F5"].Font.Color = Color.Gainsboro; worksheet.Range["F6"].Font.Color = Color.Gainsboro; worksheet.Range["F7"].Font.Color = Color.Gainsboro; // 特定セルのフォントの色を基準にソート worksheet.Sort.SortFields.Add(new FontColorSortField(worksheet.Range["F2:F7"], worksheet.Range["F7"].Font.Color, SortOrder.Ascending)); worksheet.Sort.Range = worksheet.Range["A2:F7"]; worksheet.Sort.Orientation = SortOrientation.Columns; worksheet.Sort.Apply(); // xlsx ファイルに保存 workbook.Save("SortRangeByFontColor.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim data As Object(,) = { {"名前", "地域", "生年月日", "血液型", "体重", "身長"}, {"伊達", "西地区", #1968/6/8#, "A", 67, 165}, {"上杉", "北地区", #1972/7/3#, "B", 62, 134}, {"最上", "西地区", #1964/3/2#, "O", 72, 180}, {"片倉", "南地区", #1972/8/8#, "A", 66, 163}, {"田村", "東地区", #1986/2/2#, "A", 76, 176}, {"津軽", "北地区", #1993/2/15#, "AB", 68, 145} } Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("A1:F7").Value = data worksheet.Range("A:F").ColumnWidth = 15 worksheet.Range!F2.Font.Color = Color.Red worksheet.Range!F3.Font.Color = Color.Gainsboro worksheet.Range!F4.Font.Color = Color.Green worksheet.Range!F5.Font.Color = Color.Gainsboro worksheet.Range!F6.Font.Color = Color.Gainsboro worksheet.Range!F7.Font.Color = Color.Gainsboro ' 特定セルのフォントの色を基準にソート worksheet.Sort.SortFields.Add(New FontColorSortField(worksheet.Range("F2:F7"), worksheet.Range!F7.Font.Color, SortOrder.Ascending)) worksheet.Sort.Range = worksheet.Range("A2:F7") worksheet.Sort.Orientation = SortOrientation.Columns worksheet.Sort.Apply() ' xlsx ファイルに保存 workbook.Save("SortRangeByFontColor.xlsx")