ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using HotelPms.Share.Windows.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace HotelPms.SourceFactory
{
    public partial class ExcelCopy : Form
    {
        public ExcelCopy()
        {
            InitializeComponent();
        }
 
        private void OpenExcel_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; }
            txtExcelPath.Text = openFileDialog1.FileName;
 
            cmbSheet.Items.Clear();
            comboBox1.Items.Clear();
            using (NPOIExcel excel = new NPOIExcel(txtExcelPath.Text))
            {
                for (int i = 0; i < excel.Workbook.NumberOfSheets; i++)
                {
                    cmbSheet.Items.Add(excel.Workbook.GetSheetAt(i).SheetName);
                    comboBox1.Items.Add(excel.Workbook.GetSheetAt(i).SheetName);
                }
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            List<string> srcData = new List<string>();  
            using (NPOIExcel excel = new NPOIExcel(txtExcelPath.Text))
            {
                //元
                excel.SetCurrentSheet(excel.Workbook.GetSheetIndex(cmbSheet.SelectedItem.ToString()));
                Point begin = NPOIExcel.GetCellPoint(txtSrcBegin.Text);
                Point end = NPOIExcel.GetCellPoint(txtSrcEnd.Text);
 
                for(int r = begin.Y; r <= end.Y; r++)
                {
                    srcData.Add(excel.GetCellString($"{NPOIExcel.ToColName(begin.X + 1)}{r + 1}"));
                }
 
                //コピー
                excel.SetCurrentSheet(excel.Workbook.GetSheetIndex(comboBox1.SelectedItem.ToString()));
                begin = NPOIExcel.GetCellPoint(txtDstBegin.Text);
                for (int i = 1; i <= srcData.Count; i++)
                {
                    excel.SetCell($"{NPOIExcel.ToColName(begin.X + 1)}{begin.Y + i}", srcData[i - 1]);
                }
 
                excel.Save();
            }
            MessageBox.Show("ok");
        }
    }
}