private void WriteCSVFile()
        {
            string ticker   = textTicker.Text;
            string from     = textFrom.Text;
            string to       = textTo.Text;
            string filename = ticker + "_" + from + "_to_" + to + ".csv";

            SaveFileDialog sfd = new SaveFileDialog
            {
                FileName         = filename,
                Filter           = "CSVファイル(*.csv)|*.csv",
                Title            = "保存先のファイルを選択してください",
                RestoreDirectory = true,
                OverwritePrompt  = true,
                CheckPathExists  = true
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                var quarters = GetSortedQuarters(ticker, from, to);
                if (quarters.Count == 0)
                {
                    MessageBox.Show("条件に当てはまる財務データがありませんでした。", "CSV出力", MessageBoxButtons.OK);
                    return;
                }

                using (var stream = sfd.OpenFile())
                {
                    var encoding = radioUTF8.Checked ? Encoding.UTF8 : Encoding.GetEncoding("shift_jis");
                    CSVGenerator.GenerateAndWrite(stream, encoding, quarters);
                }
                MessageBox.Show("CSVファイルを保存しました。", "CSV出力", MessageBoxButtons.OK);
            }

            DialogResult = DialogResult.OK;
            Close();
        }
        private void WriteNewSheet()
        {
            string ticker   = textTicker.Text;
            string from     = textFrom.Text;
            string to       = textTo.Text;
            var    quarters = GetSortedQuarters(ticker, from, to);

            if (quarters.Count == 0)
            {
                MessageBox.Show("条件に当てはまる財務データがありませんでした。", "CSV出力", MessageBoxButtons.OK);
                return;
            }

            // create new sheet
            Microsoft.Office.Interop.Excel.Worksheet worksheet;
            try
            {
                worksheet = BuffettCode.Globals.ThisAddIn.Application.Worksheets.Add();
            }
            catch (Exception)
            {
                MessageBox.Show("新しいシートの作成に失敗しました。", "CSV出力", MessageBoxButtons.OK);
                return;
            }

            // write header
            int row = 1;
            int col = 1;

            worksheet.Cells[col, row++] = "キー";
            worksheet.Cells[col, row++] = "項目名";
            worksheet.Cells[col, row++] = "単位";
            foreach (var quarter in quarters)
            {
                worksheet.Cells[col, row++] = quarter.FiscalYear + "Q" + quarter.FiscalQuarter;
            }

            // write values
            var propertyNames = CSVGenerator.GetPropertyNames(quarters[0]);

            foreach (var propertyName in propertyNames)
            {
                row = 1;
                col++;

                var description = quarters[0].GetDescription(propertyName);
                worksheet.Cells[col, row++] = propertyName;
                worksheet.Cells[col, row++] = description.Label;
                worksheet.Cells[col, row++] = description.Unit;
                foreach (var quarter in quarters)
                {
                    var    rawValue       = quarter.GetValue(propertyName);
                    var    formatter      = FormatterFactory.Create(description);
                    string formattedValue = formatter.Format(rawValue, description);
                    worksheet.Cells[col, row++] = formattedValue;
                }
            }
            MessageBox.Show("新しいシートを作成しました。", "CSV出力", MessageBoxButtons.OK);

            DialogResult = DialogResult.OK;
            Close();
        }