Skip to content

Commit 65ff071

Browse files
committed
Merge pull request #6 from pumpkinheader/save_sheets_a_book
Save sheets into a book
2 parents e5bb73c + 6cb9778 commit 65ff071

4 files changed

Lines changed: 46 additions & 6 deletions

File tree

reverseShift.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
11+
Debug|x86 = Debug|x86
1112
Release|Any CPU = Release|Any CPU
13+
Release|x86 = Release|x86
1214
EndGlobalSection
1315
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1416
{78E0C186-F6B8-4325-90EA-20B621CBB56D}.Debug|Any CPU.ActiveCfg = Release|Any CPU
1517
{78E0C186-F6B8-4325-90EA-20B621CBB56D}.Debug|Any CPU.Build.0 = Release|Any CPU
18+
{78E0C186-F6B8-4325-90EA-20B621CBB56D}.Debug|x86.ActiveCfg = Debug|x86
19+
{78E0C186-F6B8-4325-90EA-20B621CBB56D}.Debug|x86.Build.0 = Debug|x86
1620
{78E0C186-F6B8-4325-90EA-20B621CBB56D}.Release|Any CPU.ActiveCfg = Release|Any CPU
1721
{78E0C186-F6B8-4325-90EA-20B621CBB56D}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{78E0C186-F6B8-4325-90EA-20B621CBB56D}.Release|x86.ActiveCfg = Release|x86
23+
{78E0C186-F6B8-4325-90EA-20B621CBB56D}.Release|x86.Build.0 = Release|x86
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

reverseShift/ExcelOperator.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,22 @@ public void WriteFromArray(Object[,] datasets)
4646
var secondDimension = datasets.GetLength(1);
4747
range = worksheet.Range[worksheet.Cells[1, 1], worksheet.Cells[firstDimension, secondDimension]];
4848
range.Value2 = datasets;
49+
}
50+
public void WriteFromArray(Object[,] datasets, int sheetIndex ,string sheetName = "null")
51+
{
52+
if (sheets.Count < sheetIndex) sheets.Add();
53+
worksheet = sheets[sheetIndex];
54+
if ("null" != worksheet.Name) SetSheetName(sheetName);
55+
WriteFromArray(datasets);
56+
}
57+
public void SaveBook()
58+
{
4959
workbook.SaveAs(GetDirPath());
5060
}
61+
public void SetSheetName(string name)
62+
{
63+
worksheet.Name = name;
64+
}
5165

5266

5367
//リソースの破棄

reverseShift/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ static void Main(string[] args)
6262
//arrayに変換
6363
var positionsArray = positions.Select(p => new { Name = p.Name, Datasets = listOfListToArray(p._positions) });
6464
//Excel書き込み
65-
positionsArray.ForEach(d =>
65+
using (var excelwriter = new ExcelOperator())
6666
{
67-
using (var excelwriter = new ExcelOperator())
67+
positionsArray.Indexed().ForEach(d =>
6868
{
69-
excelwriter.fileName = d.Name + ".xlsx";
70-
excelwriter.WriteFromArray(d.Datasets);
71-
}
72-
});
69+
excelwriter.WriteFromArray(d.Element.Datasets,d.Index+1,d.Element.Name);
70+
});
71+
excelwriter.SaveBook();
72+
}
7373
}
7474

7575
public static Object[,] listOfListToArray<T>(List<List<T>> source)

reverseShift/reverseShift.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@
3131
<ErrorReport>prompt</ErrorReport>
3232
<WarningLevel>4</WarningLevel>
3333
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
35+
<DebugSymbols>true</DebugSymbols>
36+
<OutputPath>bin\x86\Debug\</OutputPath>
37+
<DefineConstants>DEBUG;TRACE</DefineConstants>
38+
<DebugType>full</DebugType>
39+
<PlatformTarget>x86</PlatformTarget>
40+
<ErrorReport>prompt</ErrorReport>
41+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
42+
<Prefer32Bit>true</Prefer32Bit>
43+
</PropertyGroup>
44+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
45+
<OutputPath>bin\x86\Release\</OutputPath>
46+
<DefineConstants>TRACE</DefineConstants>
47+
<Optimize>true</Optimize>
48+
<DebugType>pdbonly</DebugType>
49+
<PlatformTarget>x86</PlatformTarget>
50+
<ErrorReport>prompt</ErrorReport>
51+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
52+
<Prefer32Bit>true</Prefer32Bit>
53+
</PropertyGroup>
3454
<ItemGroup>
3555
<Reference Include="LinqToExcel">
3656
<HintPath>..\packages\LinqToExcel.1.10.1\lib\LinqToExcel.dll</HintPath>

0 commit comments

Comments
 (0)