Compare commits
4 Commits
e1289aebbc
...
b68a2b2107
Author | SHA1 | Date | |
---|---|---|---|
b68a2b2107 | |||
2dd664df0a | |||
ded0520756 | |||
b18e573da4 |
@ -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.9.5.1")]
|
[assembly: AssemblyVersion("1.10.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.9.5.1")]
|
[assembly: AssemblyFileVersion("1.10.0.0")]
|
||||||
[assembly: UserSecretsId("d4bb704e-14a5-421f-8f2d-0ffb66d090a2")]
|
[assembly: UserSecretsId("d4bb704e-14a5-421f-8f2d-0ffb66d090a2")]
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
<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" />
|
||||||
|
@ -21,8 +21,9 @@
|
|||||||
<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="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.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" />
|
||||||
|
@ -22,6 +22,7 @@ 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");
|
||||||
|
@ -2,6 +2,7 @@ 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;
|
||||||
@ -36,39 +37,46 @@ 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);
|
||||||
response.EnsureSuccessStatusCode();
|
if (response.IsSuccessStatusCode)
|
||||||
|
|
||||||
string jsonResponse = await response.Content.ReadAsStringAsync();
|
|
||||||
OcrResponse deserialized = JsonConvert.DeserializeObject<OcrResponse>(jsonResponse);
|
|
||||||
|
|
||||||
if (deserialized != null)
|
|
||||||
{
|
{
|
||||||
var tables = deserialized?.Result?.TextAnnotation?.Tables ?? Enumerable.Empty<Table>();
|
string jsonResponse = await response.Content.ReadAsStringAsync();
|
||||||
if (tables.Any())
|
OcrResponse deserialized = JsonConvert.DeserializeObject<OcrResponse>(jsonResponse);
|
||||||
{
|
|
||||||
List<object[,]> result = new();
|
|
||||||
foreach (var table in tables)
|
|
||||||
{
|
|
||||||
if (table.Cells == null || table.Cells.Count == 0)
|
|
||||||
{
|
|
||||||
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)
|
if (deserialized != null)
|
||||||
|
{
|
||||||
|
var tables = deserialized?.Result?.TextAnnotation?.Tables ?? Enumerable.Empty<Table>();
|
||||||
|
if (tables.Any())
|
||||||
|
{
|
||||||
|
List<object[,]> result = new();
|
||||||
|
foreach (var table in tables)
|
||||||
{
|
{
|
||||||
int rowIndex = int.Parse(cell.RowIndex);
|
if (table.Cells == null || table.Cells.Count == 0)
|
||||||
int columnIndex = int.Parse(cell.ColumnIndex);
|
{
|
||||||
cells[rowIndex, columnIndex] = double.TryParse(cell.Text, out double v) ?
|
continue;
|
||||||
v : cell.Text ?? string.Empty;
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
result.Add(cells);
|
return result;
|
||||||
}
|
}
|
||||||
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[,]>();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -55,10 +55,18 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user