Compare commits

..

No commits in common. "b68a2b210760076f2f763bb7d5a0b51c908b2647" and "e1289aebbc2cd3b2a125e910f48a8cb695997d24" have entirely different histories.

6 changed files with 31 additions and 50 deletions

View File

@ -32,6 +32,6 @@ using Microsoft.Extensions.Configuration.UserSecrets;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.10.0.0")] [assembly: AssemblyVersion("1.9.5.1")]
[assembly: AssemblyFileVersion("1.10.0.0")] [assembly: AssemblyFileVersion("1.9.5.1")]
[assembly: UserSecretsId("d4bb704e-14a5-421f-8f2d-0ffb66d090a2")] [assembly: UserSecretsId("d4bb704e-14a5-421f-8f2d-0ffb66d090a2")]

View File

@ -8,7 +8,6 @@
<Reference Path="Microsoft.Extensions.Caching.Memory.dll" Pack="true" /> <Reference Path="Microsoft.Extensions.Caching.Memory.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Configuration.Abstractions.dll" Pack="true" /> <Reference Path="Microsoft.Extensions.Configuration.Abstractions.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Configuration.dll" Pack="true" /> <Reference Path="Microsoft.Extensions.Configuration.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Configuration.EnvironmentVariables.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Configuration.FileExtensions.dll" Pack="true" /> <Reference Path="Microsoft.Extensions.Configuration.FileExtensions.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Configuration.Json.dll" Pack="true" /> <Reference Path="Microsoft.Extensions.Configuration.Json.dll" Pack="true" />
<Reference Path="Microsoft.Extensions.Configuration.UserSecrets.dll" Pack="true" /> <Reference Path="Microsoft.Extensions.Configuration.UserSecrets.dll" Pack="true" />

View File

@ -21,9 +21,8 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageReference Include="netDxf" Version="2022.11.2" /> <PackageReference Include="netDxf" Version="2022.11.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

View File

@ -22,7 +22,6 @@ public class AddInConfiguration : IAddInConfiguration
{ {
_configuration = new ConfigurationBuilder() _configuration = new ConfigurationBuilder()
.AddUserSecrets<RhSolutionsAddIn>() .AddUserSecrets<RhSolutionsAddIn>()
.AddEnvironmentVariables("RHS_ADDIN__")
.Build(); .Build();
_rootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RhSolutions\RhSolutions-AddIn"); _rootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RhSolutions\RhSolutions-AddIn");

View File

@ -2,7 +2,6 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace RhSolutions.Services; namespace RhSolutions.Services;
@ -37,46 +36,39 @@ public class YandexOcrClient : IOcrClient
_httpClient.DefaultRequestHeaders.Add("x-data-logging-enable", "true"); _httpClient.DefaultRequestHeaders.Add("x-data-logging-enable", "true");
using HttpResponseMessage response = await _httpClient.PostAsync("recognizeText", jsonContent); using HttpResponseMessage response = await _httpClient.PostAsync("recognizeText", jsonContent);
if (response.IsSuccessStatusCode) response.EnsureSuccessStatusCode();
string jsonResponse = await response.Content.ReadAsStringAsync();
OcrResponse deserialized = JsonConvert.DeserializeObject<OcrResponse>(jsonResponse);
if (deserialized != null)
{ {
string jsonResponse = await response.Content.ReadAsStringAsync(); var tables = deserialized?.Result?.TextAnnotation?.Tables ?? Enumerable.Empty<Table>();
OcrResponse deserialized = JsonConvert.DeserializeObject<OcrResponse>(jsonResponse); if (tables.Any())
if (deserialized != null)
{ {
var tables = deserialized?.Result?.TextAnnotation?.Tables ?? Enumerable.Empty<Table>(); List<object[,]> result = new();
if (tables.Any()) foreach (var table in tables)
{ {
List<object[,]> result = new(); if (table.Cells == null || table.Cells.Count == 0)
foreach (var table in tables)
{ {
if (table.Cells == null || table.Cells.Count == 0) continue;
{
continue;
}
int columnCount = int.Parse(table.ColumnCount);
int rowCount = int.Parse(table.RowCount);
object[,] cells = new object[rowCount, columnCount];
foreach (Cell cell in table.Cells)
{
int rowIndex = int.Parse(cell.RowIndex);
int columnIndex = int.Parse(cell.ColumnIndex);
cells[rowIndex, columnIndex] = double.TryParse(cell.Text, out double v) ?
v : cell.Text ?? string.Empty;
}
result.Add(cells);
} }
return result; int columnCount = int.Parse(table.ColumnCount);
int rowCount = int.Parse(table.RowCount);
object[,] cells = new object[rowCount, columnCount];
foreach (Cell cell in table.Cells)
{
int rowIndex = int.Parse(cell.RowIndex);
int columnIndex = int.Parse(cell.ColumnIndex);
cells[rowIndex, columnIndex] = double.TryParse(cell.Text, out double v) ?
v : cell.Text ?? string.Empty;
}
result.Add(cells);
} }
return result;
} }
} }
else
{
string content = await response.Content.ReadAsStringAsync();
MessageBox.Show($"{response.StatusCode}: {content}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return Enumerable.Empty<object[,]>(); return Enumerable.Empty<object[,]>();
} }
} }

View File

@ -55,18 +55,10 @@ internal class OcrTool : ITool
{ {
Range excelCell = app.ActiveSheet.Cells(currentCell.Row + row, Range excelCell = app.ActiveSheet.Cells(currentCell.Row + row,
currentCell.Column + column); currentCell.Column + column);
excelCell.Value2 = table[row, column]; excelCell.Value2 = table[row,column];
excelCell.EntireColumn.AutoFit();
excelCell.EntireRow.AutoFit();
} }
foreach (Range row in tableRange.Rows)
{
row.EntireRow.AutoFit();
}
foreach (Range column in tableRange.Columns)
{
column.EntireColumn.AutoFit();
}
app.ActiveSheet.Cells(currentCell.Row + rowCount + 1, currentCell.Column).Activate(); app.ActiveSheet.Cells(currentCell.Row + rowCount + 1, currentCell.Column).Activate();
} }
} }