private FlatDataSource CreateDataSource(Stream fileStream)
{
FlatDataSource flatDataSource = new FlatDataSource();
ExcelDataConnectionSettings excelDataConnectionSettings =
new ExcelDataConnectionSettings
{
FileStream = fileStream,
GeneratedTypeName = "ExcelData",
WorksheetName = "Sheet1"
};
string excelStringFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)";
string systemValueFormat = "{0:C3}";
ExcelDataConnectionSettings.AddExcelCellFormatMapping(
excelStringFormat, systemValueFormat);
flatDataSource.Cube = DataSourceBase.GenerateInitialCube("ExcelData");
//以下の 3 行は
//行と列の階層を選択します
//メジャーも選択します。自身の名前を使用する
//必要があります
flatDataSource.Rows =
DataSourceBase.GenerateInitialItems("[Region].[Region]");
flatDataSource.Columns =
DataSourceBase.GenerateInitialItems("[Date].[Date]");
flatDataSource.Measures =
DataSourceBase.GenerateInitialItems("Units");
//これらをスキップしてデータ セレクターを使用することも可能です
flatDataSource.ConnectionSettings = excelDataConnectionSettings;
flatDataSource.CubesSettings.Add(
new CubeMetadata
{
DataTypeFullName = "ExcelData",
DisplayName = "Sheet1 Data"
});
HierarchyDescriptor stringDataDescriptor =
new HierarchyDescriptor
{
AppliesToPropertiesOfType = typeof(string)
};
stringDataDescriptor.AddLevel<string>(s => "All","All values");
stringDataDescriptor.AddLevel<string>(s => s, "Members");
HierarchyDescriptor dateTimeDescriptor =
new HierarchyDescriptor
{
AppliesToPropertiesOfType = typeof(DateTime)
};
dateTimeDescriptor.AddLevel<DateTime>(date => "All Dates", "All Values");
dateTimeDescriptor.AddLevel<DateTime>(date => date.Year, "Years");
dateTimeDescriptor.AddLevel<DateTime>(date => date.Date, "Members");
flatDataSource.HierarchyDescriptors.Add(stringDataDescriptor);
flatDataSource.HierarchyDescriptors.Add(dateTimeDescriptor);
return flatDataSource;
}