Skip to content

Commit

Permalink
Merge pull request #4 from SergeyLadanov/GemBox
Browse files Browse the repository at this point in the history
Gem box
  • Loading branch information
SergeyLadanov authored Nov 2, 2023
2 parents 8b225b3 + b43ac41 commit 3f23a7b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
3 changes: 1 addition & 2 deletions CPL_Converter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GemBox.Spreadsheet" Version="49.0.1509" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1001" />
<PackageReference Include="Open-XML-SDK" Version="2.9.1" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
</Project>
56 changes: 38 additions & 18 deletions CplConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
using System.IO;


using System.Reflection;

using GemBox.Spreadsheet;
using System.Runtime.Versioning;
using System.Windows.Forms;

namespace CPL_Converter
{
class CplConverter
Expand Down Expand Up @@ -81,37 +87,38 @@ private String[] ParseRow(String Input)

return Result;
}




[SupportedOSPlatform("windows")]

// Сохранение данных в MS Excel
private int OutInExcel(StreamReader inputSr)
{
String Line;
String[] RowData;
int RowCount = 2;
// Создаём объект - экземпляр нашего приложения
Excel.Application excelApp = new Excel.Application();
// Создаём экземпляр рабочей книги Excel
Excel.Workbook workBook;
// Создаём экземпляр листа Excel
Excel.Worksheet workSheet;
workBook = excelApp.Workbooks.Add();
workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(1);

SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

ExcelFile workbook = new ExcelFile();
var worksheet = workbook.Worksheets.Add("List1");


// Заполнение шапки таблицы
for (int i = 1; i <= ColumnNames.Length; i++)
{
workSheet.Cells[1, i] = ColumnNames[i - 1];
worksheet.Cells[0, i - 1].Value = ColumnNames[i - 1];
}

// Заполнение данными
while ((Line = inputSr.ReadLine()) != null)
{
Line = LineCorrection(Line);
RowData = ParseRow(Line);
for (int i = 1; i <= ColumnCount; i++)
{
workSheet.Cells[RowCount, i] = RowData[i - 1];
worksheet.Cells[RowCount - 1, i - 1].Value = RowData[i - 1];
}

RowCount++;
Expand All @@ -120,20 +127,33 @@ private int OutInExcel(StreamReader inputSr)
// Сохранение данных
if (AutoSave)
{
workBook.SaveAs(FilePath);
workBook.Close();
workbook.Save(FilePath);
}
else
{
excelApp.Visible = true;
excelApp.UserControl = true;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.Title = "Путь для сохранения файла";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
workbook.Save(saveFileDialog1.FileName);
}
else
{

}
}


// Возврат количество обработанных строк
return RowCount - 2;
}


[SupportedOSPlatform("windows")]
public int HandleCPL(String InputFileName)
{
int RowCount = 0;
Expand Down
3 changes: 3 additions & 0 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -55,6 +56,7 @@ public Form1()
InitializeComponent();
}
// Обработка нажатия кнопки
[SupportedOSPlatform("windows")]
private void OpenButton_Click(object sender, EventArgs e)
{

Expand All @@ -74,6 +76,7 @@ private void OpenButton_Click(object sender, EventArgs e)
//conv.HandleCPL("D:\\WorkSpace\\FrequencyRegulator\\freqreq_control\\Pick Place\\CPL.txt");
}

[SupportedOSPlatform("windows")]
private void Form1_Load(object sender, EventArgs e)
{
// Не показывать форму при запуске
Expand Down

0 comments on commit 3f23a7b

Please sign in to comment.