Excel неверно выводит данные

This commit is contained in:
Артём Алейкин 2023-11-30 01:39:27 +04:00
parent 9de3a512ef
commit 3704947e84
3 changed files with 52 additions and 2 deletions

View File

@ -40,6 +40,7 @@
this.сформироватьExcelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.сформироватьExcelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.documentWithImage1 = new WinFormsLibrary.DocumentWithImage(this.components); this.documentWithImage1 = new WinFormsLibrary.DocumentWithImage(this.components);
this.table2column1 = new WinFormsLibrary.Table2column(this.components); this.table2column1 = new WinFormsLibrary.Table2column(this.components);
this.componentDocumentWithChartBarExcel1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarExcel(this.components);
this.contextMenuStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -112,6 +113,7 @@
this.сформироватьExcelToolStripMenuItem.Name = "сформироватьExcelToolStripMenuItem"; this.сформироватьExcelToolStripMenuItem.Name = "сформироватьExcelToolStripMenuItem";
this.сформироватьExcelToolStripMenuItem.Size = new System.Drawing.Size(204, 22); this.сформироватьExcelToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
this.сформироватьExcelToolStripMenuItem.Text = "Сформировать Excel"; this.сформироватьExcelToolStripMenuItem.Text = "Сформировать Excel";
this.сформироватьExcelToolStripMenuItem.Click += new System.EventHandler(this.сформироватьExcelToolStripMenuItem_Click);
// //
// FormMain // FormMain
// //
@ -140,5 +142,6 @@
private ToolStripMenuItem сформироватьExcelToolStripMenuItem; private ToolStripMenuItem сформироватьExcelToolStripMenuItem;
private WinFormsLibrary.DocumentWithImage documentWithImage1; private WinFormsLibrary.DocumentWithImage documentWithImage1;
private WinFormsLibrary.Table2column table2column1; private WinFormsLibrary.Table2column table2column1;
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarExcel componentDocumentWithChartBarExcel1;
} }
} }

View File

@ -1,3 +1,4 @@
using ComponentsLibraryNet60.Models;
using Contracts.StorageContracts; using Contracts.StorageContracts;
using Contracts.ViewModels; using Contracts.ViewModels;
using ControlsLibraryNet60.Data; using ControlsLibraryNet60.Data;
@ -174,14 +175,57 @@ namespace AppView
new ColumnDefinition{Header = "-", PropertyName = "Number", Weight = 30}, new ColumnDefinition{Header = "-", PropertyName = "Number", Weight = 30},
}; };
var orders = _providerStorage.GetFullList(); var providers = _providerStorage.GetFullList();
List<int[]> mergedColums = new() { new int[] { 1, 2 } }; List<int[]> mergedColums = new() { new int[] { 1, 2 } };
BigTable<ProviderViewModel> info = new(fileName, "Table", columnDefinitionsUp, columnDefinitionsDown, orders, mergedColums); BigTable<ProviderViewModel> info = new(fileName, "Table", columnDefinitionsUp, columnDefinitionsDown, providers, mergedColums);
table2column1.CreateTable(info); table2column1.CreateTable(info);
MessageBox.Show("Ãîòîâî"); MessageBox.Show("Ãîòîâî");
} }
private void ñôîðìèðîâàòüExcelToolStripMenuItem_Click(object sender, EventArgs e)
{
string fileName = "";
using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
fileName = dialog.FileName.ToString();
MessageBox.Show("Âûïîëíåíî", "Óñïåõ", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
var providers = _providerStorage.GetFullList();
var uniqueTypes = providers.Select(p => p.Type).Distinct();
Dictionary<string, List<(int Date, double Value)>> data = new Dictionary<string, List<(int Date, double Value)>>();
foreach (var uniqueType in uniqueTypes)
{
var typeProviders = providers.Where(p => p.Type == uniqueType).ToList();
var dataList = new List<(int Date, double Value)>();
for (int i = 0; i < typeProviders.Count; i++)
{
dataList.Add((i + 1, i + 1)); // Ïðîñòî ïðèìåð äàííûõ (Date, Value), âû ìîæåòå èñïîëüçîâàòü ñâîè äàííûå
}
data.Add(uniqueType, dataList);
}
componentDocumentWithChartBarExcel1.CreateDoc(new ComponentDocumentWithChartConfig()
{
FilePath = fileName,
Header = "Ñâîäêà ïî òèïàì èçäåëèÿ.",
ChartTitle = "Êîëè÷åñòâî ïîñòàâùèêîâ äëÿ òîâàðîâ êàæäîãî òèïà",
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
Data = data
});
}
} }
} }

View File

@ -66,4 +66,7 @@
<metadata name="table2column1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="table2column1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>345, 17</value> <value>345, 17</value>
</metadata> </metadata>
<metadata name="componentDocumentWithChartBarExcel1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>478, 17</value>
</metadata>
</root> </root>