클립보드의 행 개수에 따라 FarPoint Spread에 행을 추가하면서 데이터를 붙여넣는 샘플로직으로 정상동작하는지 구현 테스트 필요.
using System;
using System.Windows.Forms;
using FarPoint.Win.Spread;
namespace SpreadClipboardPaste
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void PasteWithRowAddition(FpSpread spread)
{
try
{
// 클립보드 내용 가져오기
string clipboardText = Clipboard.GetText();
if (string.IsNullOrEmpty(clipboardText))
{
MessageBox.Show("클립보드에 데이터가 없습니다.", "알림", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// 클립보드 데이터를 줄 단위로 나누기
string[] rows = clipboardText.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
if (rows.Length == 0)
{
MessageBox.Show("클립보드 데이터가 비어 있습니다.", "알림", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// 활성 시트 가져오기
var activeSheet = spread.ActiveSheet;
// 선택된 셀이 없으면 첫 번째 셀로 설정
int startRow = 0;
int startColumn = 0;
var selection = activeSheet.GetSelection(0);
if (selection != null)
{
startRow = selection.Row >= 0 ? selection.Row : 0;
startColumn = selection.Column >= 0 ? selection.Column : 0;
}
// 행 추가 및 데이터 삽입
for (int i = 0; i < rows.Length; i++)
{
string[] cells = rows[i].Split('\t');
// 필요하면 행 추가
if (startRow + i >= activeSheet.RowCount)
{
activeSheet.RowCount++;
}
for (int j = 0; j < cells.Length; j++)
{
// 열 범위 체크 및 데이터 삽입
if (startColumn + j < activeSheet.ColumnCount)
{
activeSheet.Cells[startRow + i, startColumn + j].Text = cells[j];
}
}
}
}
catch (Exception ex)
{
MessageBox.Show($"오류 발생: {ex.Message}", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnPaste_Click(object sender, EventArgs e)
{
PasteWithRowAddition(fpSpread1); // fpSpread1은 FpSpread 컨트롤의 이름입니다.
}
}
}
'일기장 - 아둘파' 카테고리의 다른 글
| 넷플릭스 무료이용 해지 방법 안내 (0) | 2021.01.22 |
|---|---|
| [건강] 비중격만곡증 수술 후기, 비염, 축농증 (0) | 2020.02.13 |
| 티스토리 블로그 본문에 애드센스 삽입 (0) | 2020.02.05 |
| 티스토리 블로그 스킨 변경 및 애드센스 최적화 작업 진행. (1) | 2020.02.04 |
| [cafe] 용인 카페 어 로프 슬라이스 피스 (2) | 2020.02.03 |
| [부동산] 마장택지지구 산책 풍경 (0) | 2019.01.20 |
| [먹을거리] 이천 아젤리아카페 (0) | 2018.01.01 |
| [oracle] PreparedStatement like 검색 방법 (0) | 2013.09.11 |
댓글