I'm currently looping through a JSON array and generating an object for each item in the array.
I wondering how I can parse data from the current object.
int i = 0, count = 0, yMP, yGP, yGT, favscountB8 = 0;
string gamertag;
JObject o1 = JObject.Parse(File.ReadAllText(#"gamerprofile.json"));
string jsonGamerprofile = JsonConvert.SerializeObject(o1);
var resultObjects = AllChildren(JObject.Parse(jsonGamerprofile))
.First(c => c.Type == JTokenType.Array && c.Path.Contains("favorites"))
.Children<JObject>();
foreach (JObject result in resultObjects)
{
// Here I wish to make the string gamertag = the value of (FavsGTS_gpF) which is inside the current object.
favscountB8 = favscountB8 + 1;
count = count + 1;
yMP = 6 + (62 * (count - 1));
yGP = 7 + (62 * (count - 1));
yGT = 11 + (62 * (count - 1));
Panel mainpanel1 = new Panel();
PictureBox gamerpic1 = new PictureBox();
Label gamertag1 = new Label();
mainpanel1.BackColor = Color.Red;
mainpanel1.Location = new Point(6, yMP);
mainpanel1.Size = new Size(957, 60);
mainpanel1.Name = "mainpanel" + i.ToString();
gamerpic1.BackColor = Color.Azure;
gamerpic1.Location = new Point(7, yGP);
gamerpic1.Size = new Size(54, 54);
gamerpic1.Name = "gamerpic" + i.ToString();
gamerpic1.BringToFront();
gamertag1.ForeColor = Color.FromArgb(110, 120, 127);
gamertag1.BackColor = Color.White;
gamertag1.Text = "Gamertag " + count.ToString();
gamertag1.Font = new Font("Arial Narrow", 14, FontStyle.Bold);
gamertag1.Location = new Point(76, yGT);
gamertag1.Size = new Size(145, 23);
gamertag1.Name = "Gamertag " + count.ToString();
gamertag1.BringToFront();
i = i + 1;
panel4.Controls.Add(gamertag1);
panel4.Controls.Add(gamerpic1);
panel4.Controls.Add(mainpanel1);
}
Inside the foreach statement I wish to make the "gamertag" string equal to the value of "FavsGTS_gpF" which is in each object in the array.
Related
For last 2 days I stuck with a line chart issue with EPPlus. My objective is to create a line chart with EPPlus and line style will be dash line like below image. picture attached.
I search a lot Google for 2 days still got no relevant hint to have dash line in chart. I am not sure that at all EPPlus support dash line. I am using EPPlus version 6.0 and .NET Framework version 4.8. This is a sample code which generate chart in excel sheet with one line but I need that line will be dash line. please someone see my code and tell me what is missing in my code for which I could not have dash line style of line chart.
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
var newFile = new FileInfo(filepath);
using (ExcelPackage xlPackage = new ExcelPackage(newFile))
{
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("test");
worksheet.Cells["A1"].Value = 1;
worksheet.Cells["A2"].Value = 2;
worksheet.Cells["A3"].Value = 3;
worksheet.Cells["A4"].Value = 4;
worksheet.Cells["A5"].Value = 5;
worksheet.Cells["A6"].Value = 6;
worksheet.Cells["B1"].Value = 10000;
worksheet.Cells["B2"].Value = 10100;
worksheet.Cells["B3"].Value = 10200;
worksheet.Cells["B4"].Value = 10150;
worksheet.Cells["B5"].Value = 10250;
worksheet.Cells["B6"].Value = 10200;
//ExcelChart chart = worksheet.Drawings.AddChart("LineChart", eChartType.XYScatterSmooth);
ExcelChart chart = worksheet.Drawings.AddChart("LineChart", eChartType.XYScatterSmoothNoMarkers);
chart.Series.Add(ExcelRange.GetAddress(1, 2, worksheet.Dimension.End.Row, 2),
ExcelRange.GetAddress(1, 1, worksheet.Dimension.End.Row, 1));
var Series = chart.Series[0];
//chart.Axis[0].MinorGridlines.Fill.Color = Color.Red;
//chart.Axis[0].MinorGridlines.LineStyle = eLineStyle.LongDashDot;
chart.Axis[0].RemoveGridlines();
chart.Axis[1].RemoveGridlines();
chart.Axis[0].Border.LineStyle = eLineStyle.SystemDash;
//chart.XAxis.Border.LineStyle = eLineStyle.Dash;
chart.Series[0].Header = "Blah";
//chart.Series[0].Border.LineStyle = eLineStyle.DashDot;
//chart.Axis[0].Border.LineStyle = eLineStyle.Dash;
xlPackage.Save();
MessageBox.Show("Done");
}
I also check this post but could not implement it in my code Office Open XML: Drawing Dashed Line in Chart
Please push me to right direction to achieve my goal. Thanks in advance.
This works for me with same versions as you.
You need to add a reference to System.Drawing for the color:
// ...(code above this line did not change)
ExcelChart chart = worksheet.Drawings.AddChart("LineChart", eChartType.XYScatterSmoothNoMarkers);
chart.Series.Add(
ExcelRange.GetAddress(1, 2, worksheet.Dimension.End.Row, 2),
ExcelRange.GetAddress(1, 1, worksheet.Dimension.End.Row, 1));
chart.Series[0].Header = "Blah";
// Add this:
chart.Series[0].Border.LineStyle = OfficeOpenXml.Drawing.eLineStyle.Dash;
chart.Series[0].Border.Width = 2;
chart.Series[0].Border.Fill.Color = System.Drawing.Color.Blue;
chart.Axis[0].RemoveGridlines();
chart.Axis[1].RemoveGridlines();
xlPackage.Save();
Result:
#region chart summary 4
ExcelWorksheet Worksheet4 = p.Workbook.Worksheets.Add("Graph(4)");
var summary_Chart_four = Worksheet4.Drawings.AddChart("chart", eChartType.LineMarkers);
// var summary_Chart_four = Worksheet4.Drawings.AddChart("chart", eChartType.XYScatterLines) as ExcelScatterChart;
//var summary_Chart_four = Worksheet4.Drawings.AddChart("chart", (eChartType)System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash);
//var summary_Chart_four = myWorksheet.Drawings.AddChart("chart", (eChartType)System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash);
summary_Chart_four.ShowDataLabelsOverMaximum = true;
Worksheet4.Cells.Style.Font.Name = "Arial";
Worksheet4.Cells.Style.Font.Size = 10;
Worksheet4.Cells.Style.Font.Bold = false;
loopCnt = 0;
for (int i = 0; i < (cVM.PeerGroups.Count + cVM.IndexGroups.Count) * 4; i += 4)
{
int rowIndex = 10 + i;
int endRowIndex = 14 + i;
string startingColumn_series = "C" + rowIndex;
string endColumn_series = column + rowIndex;
string lastColumn_xaxis = column + 6;
int headerRowIndex = 9 + i;
string seriesHeader = "A" + headerRowIndex;
var series_i = summary_Chart_four.Series.Add(myWorksheet_summary_data.Cells[startingColumn_series + ":" + endColumn_series], myWorksheet_summary_data.Cells["C6:" + lastColumn_xaxis]);//working
series_i.Header = myWorksheet_summary_data.Cells[seriesHeader].Value.ToString();
summary_Chart_four.YAxis.Font.Size = 10;
summary_Chart_four.XAxis.Font.Size = 10;
//summary_Chart_four.XAxis.Format =DateTime.Now.Year.ToString();
summary_Chart_four.YAxis.Format = "$0";
if (loopCnt == 0)
{
string LineColor = "#000080";
series_i.Border.LineStyle = eLineStyle.Solid;
//series_i.LineColor = LineColor.ConvertToColor();
//series_i.LineWidth = 2.0;
//series_i.Marker.Style = eMarkerStyle.Diamond;
//series_i.Marker.Size = 8;
//string BGColor = "#99ccff";
//series_i.Marker.Fill.Color = BGColor.ConvertToColor();
//string strBorderColor = "#000080";
//series_i.Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineColor = LineColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineWidth = 2.0;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Diamond;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Size = 8;
string BGColor = "#99ccff";
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.LineCap
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Fill.Color = BGColor.ConvertToColor();
string strBorderColor = "#000080";
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Width = 0.75;
}
else if (loopCnt == 1)
{
string LineColor = "#003300";
series_i.Border.LineStyle = eLineStyle.LongDash;
//series_i.LineColor = LineColor.ConvertToColor();
//series_i.LineWidth = 2.0;
//series_i.Marker.Style = eMarkerStyle.Square;
////((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Dash;
//series_i.Marker.Size = 7;
string BGColor = "#c0c0c0";
//series_i.Marker.Fill.Color = BGColor.ConvertToColor();
//string strBorderColor = "#003300";
//series_i.Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineColor = LineColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineWidth = 2.0;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Square;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Size = 7;
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.LineCap
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Fill.Color = BGColor.ConvertToColor();
string strBorderColor = "#003300";
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Width = 0.75;
}
else if (loopCnt == 2)
{
string LineColor = "#F79646";
series_i.Border.LineStyle = eLineStyle.Dot;
////series_i.LineColor = LineColor.ConvertToColor();
////series_i.LineWidth = 2.0;
////series_i.Marker.Style = eMarkerStyle.Circle;
//////((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Dot;
////series_i.Marker.Size = 8;
string BGColor = "#ccffcc";
////series_i.Marker.Fill.Color = BGColor.ConvertToColor();
string strBorderColor = "#F79646";
////series_i.Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineColor = LineColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineWidth = 2.0;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Circle;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Size = 8;
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.LineCap
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Fill.Color = BGColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Width = 0.75;
}
else if (loopCnt == 3)
{
string LineColor = "#c0504d";
series_i.Border.LineStyle = eLineStyle.LongDashDotDot;
////series_i.LineColor = LineColor.ConvertToColor();
////series_i.LineWidth = 2.0;
////series_i.Marker.Style = eMarkerStyle.Triangle;
//////((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Dot;
////series_i.Marker.Size = 8;
string BGColor = "#c0504d";
////series_i.Marker.Fill.Color = BGColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineColor = LineColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineWidth = 2.0;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Triangle;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Size = 8;
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.LineCap
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Fill.Color = BGColor.ConvertToColor();
string strBorderColor = "#003300";
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Width = 0.75;
}
//else if (loopCnt == 4)
//{
// string LineColor = "#c0504d";
// series_i.Border.LineStyle = eLineStyle.LongDashDotDot;
// series_i.LineColor = LineColor.ConvertToColor();
// series_i.LineWidth = 1.5;
// series_i.Marker.Style = eMarkerStyle.Square;
// //((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Dot;
// series_i.Marker.Size = 8;
// string BGColor = "#c0504d";
// series_i.Marker.Fill.Color = BGColor.ConvertToColor();
//}
else
{
////series_i.LineColor = System.Drawing.Color.Aqua;
////series_i.LineWidth = 1.5;
////series_i.Marker.Style = eMarkerStyle.Circle;
////series_i.Marker.Size = 8;
////series_i.Marker.Fill.Color = System.Drawing.Color.Aqua;
}
//series_i.Smooth = eLineStyle.Dash;
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Series=eChartType.d
loopCnt++;
}
//var series_four = summary_Chart_four.Series.Add(myWorksheet_summary_data.Cells["C10:" + lastColumn_series1], myWorksheet_summary_data.Cells["C6:" + lastColumn_xaxis]);//working
//series_four.Header = myWorksheet_summary_data.Cells["A9"].Value.ToString();
//var series_four1 = summary_Chart_four.Series.Add(myWorksheet_summary_data.Cells["C14:" + lastColumn_series2], myWorksheet_summary_data.Cells["C6:" + lastColumn_xaxis]);
//series_four1.Header = myWorksheet_summary_data.Cells["A13"].Value.ToString();
summary_Chart_four.Border.Fill.Color = System.Drawing.Color.Black;
//summary_Chart_four.Title.Text = "Comparison of " + cVM.YearsBack + " Year Cumulative Total Return" + Environment.NewLine + " Assumes Initial Investment of $100" + Environment.NewLine + strMonth + " " + strSelectedDt.Year;
summary_Chart_four.Title.Text = "COMPARISON OF CUMULATIVE TOTAL RETURN";
summary_Chart_four.SetSize(960, 600);
// Add to 6th row and to the 6th column
summary_Chart_four.Legend.Font.Size = 10;
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).Legend.Font.SetFromFont("Calibri", 11, false, false, false, false);
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).YAxis.Font.SetFromFont("Arial", 10, false, false, false, false);
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).XAxis.Font.SetFromFont("Arial", 10, false, false, false, false);
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).Title.Font.Bold = true;
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).Title.Font.SetFromFont("Calibri", 16, false, false, false, false);
//summary_Chart_four.Legend.Border.Fill.Color = System.Drawing.Color.Black;
summary_Chart_four.SetPosition(0, 0, 0, 0);
summary_Chart_four.XAxis.MajorTickMark = eAxisTickMark.In;
//summary_Chart.XAxis.MajorTickMark = eAxisTickMark.In;
summary_Chart_four.XAxis.MinorTickMark = eAxisTickMark.None;
summary_Chart_four.YAxis.MinorTickMark = eAxisTickMark.None;
summary_Chart_four.Legend.Position = eLegendPosition.Top;
summary_Chart_four.YAxis.CrossBetween = eCrossBetween.MidCat;
summary_Chart_four.XAxis.MajorGridlines.CompoundLineStyle = eCompundLineStyle.Double;
I have created report in excel sheet which Is described in image1 and this image should give redar diagram which in in Image2 in different excel sheet like given in screenshot.
there are two excel sheet in one excel as you can see in screenshot so in chart sheet there should be redar diagram and sheet named sheet there is excel report valud as you can see in screenshot
I have already done piechart and excel report as well and I get stocked while making redar diagram ,
example of that I had made piechart and excel report :
public static class TestRunTestCaseExportHelper {
public static byte[] TestRunTestCaseByTestRunIdToExcel(List<TestRunTestCaseExportModel> data1, List<TestRunTestCaseExportTestResultCountModel> datas, List<FunctionModuleModel> funcitonData, TestRunTestCaseCountPercentageModel testRunStatusCountPercentage)
{
try
{
byte[] result;
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using (var package = new ExcelPackage())
{
int cellNumb = 1;
string[] totalColumns = {
"SN",
"Test Case",
"Test Plan",
"Status"
};
string[] totalColumn = {
"Test Plan",
"Passed",
"Failed",
"Pending",
"Blocked",
};
string[] totalColumn3 = {
"Function",
"Count"
};
string[] totalColumn4 = {
"Status",
"Percentage",
};
var worksheet = package.Workbook.Worksheets.Add("Chart");
var worksheets = package.Workbook.Worksheets.Add("sheet");
//worksheet.InsertRow(5, 2);
var rand = new Random();
var testRunStatusCountPercentages = testRunStatusCountPercentage;
var data = new List<KeyValuePair<string, int>>
{
new KeyValuePair<string, int>("Passed", testRunStatusCountPercentages.PassedPercentage),
new KeyValuePair<string, int>("Failed", testRunStatusCountPercentages.FailedPercentage),
new KeyValuePair<string, int>("Pending",85),
new KeyValuePair<string, int>("Blocked", 15),
};
for (var i = 0; i < totalColumn4.Length; i++)
{
worksheets.Cells[1, i + 16].Value = totalColumn4[i]; //populate header row
}
var m = 2;
//Fill the table
var startCell = worksheets.Cells[1, 16];
if (testRunStatusCountPercentage != null)
{
for (var i = 0; i < data.Count(); i++)
{
startCell.Offset(i + 1, 0).Value = data[i].Key;
startCell.Offset(i + 1, 1).Value = data[i].Value;
}
using (ExcelRange Rng = worksheets.Cells[1, 16, 5, data.Count + 13])
{
Rng.Style.Border.Top.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Left.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Right.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
}
}
//Add the chart to the sheet
var pieChart = worksheet.Drawings.AddChart("Chart1", eChartType.Pie);
pieChart.SetPosition(data.Count + 1, 0, 0, 0);
pieChart.Title.Text = "Test Case Excution Status";
pieChart.Title.Font.Bold = true;
pieChart.Title.Font.Size = 12;
//Set the data range
var series = pieChart.Series.Add(worksheets.Cells[2, 17, data.Count + 1, 17], worksheets.Cells[2, 16, data.Count + 1, 16]);
var pieSeries = (ExcelPieChartSerie)series;
pieSeries.Explosion = 5;
//Format the labels
pieSeries.DataLabel.Font.Bold = true;
pieSeries.DataLabel.ShowValue = true;
pieSeries.DataLabel.ShowPercent = true;
pieSeries.DataLabel.ShowLeaderLines = true;
pieSeries.DataLabel.Separator = ";";
pieSeries.DataLabel.Position = eLabelPosition.BestFit;
//Format the legend
pieChart.Legend.Add();
pieChart.Legend.Border.Width = 0;
pieChart.Legend.Font.Size = 12;
pieChart.Legend.Font.Bold = true;
pieChart.Legend.Position = eLegendPosition.Right;
// add a new worksheet to the empty workbook
using (var cells = worksheets.Cells[1, 1, 1, totalColumns.Length]) //(1,1) => (1,10)
{
cells.Style.Font.Bold = true;
}
using (var cells = worksheets.Cells[1, 7, 1, totalColumn.Length + 7]) //(1,1) => (1,10)
{
cells.Style.Font.Bold = true;
}
using (var cells = worksheets.Cells[1, 13, 1, totalColumn3.Length + 13]) //(1,1) => (1,10)
{
cells.Style.Font.Bold = true;
}
using (var cells = worksheets.Cells[1, 16, 1, totalColumn4.Length + 16]) //(1,1) => (1,10)
{
cells.Style.Font.Bold = true;
}
var records = data1.ToList();
var list = datas.ToList();
var funValue = funcitonData.ToList();
int totalRows = data1.Count + 1; //data including header row
int totalRowsList = datas.Count + 2;
var totalRowsForFuntion = funcitonData.Count + 1;
for (var i = 0; i < totalColumns.Length; i++)
{
worksheets.Cells[1, i + 1].Value = totalColumns[i]; //populate header row
}
for (var i = 0; i < totalColumn.Length; i++)
{
worksheets.Cells[1, i + 7].Value = totalColumn[i]; //populate header row
}
for (var i = 0; i < totalColumn3.Length; i++)
{
worksheets.Cells[1, i + 13].Value = totalColumn3[i]; //populate header row
}
//Add values
var j = 2; //to start data from second row after the header row.
var k = 2;
var l = 2;
if (data1 != null)
{
foreach (var item in records)
{
worksheets.Cells["A" + j].Value = cellNumb;
worksheets.Cells["B" + j].Value = item.TestCaseName;
worksheets.Cells["C" + j].Value = item.TestPlanName;
worksheets.Cells["D" + j].Value = item.Status;
j++;
cellNumb++;
}
using (ExcelRange Rng = worksheets.Cells[1, 1, totalRows, totalColumns.Length])
{
Rng.Style.Border.Top.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Left.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Right.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
}
}
if (datas != null)
{
foreach (var item in datas)
{
worksheets.Cells["G" + k].Value = item.TestPlanNameForCount;
worksheets.Cells["H" + k].Value = item.TotalPassedCount;
worksheets.Cells["I" + k].Value = item.TotalFailedCount;
worksheets.Cells["J" + k].Value = item.TotalPendingCount;
worksheets.Cells["K" + k].Value = item.TotalBlockCount;
k++;
}
worksheets.Cells["G" + k].Value = "Total";
worksheets.Cells["H" + k].Value = datas.Sum(x => x.TotalPassedCount);
worksheets.Cells["I" + k].Value = datas.Sum(x => x.TotalFailedCount);
worksheets.Cells["J" + k].Value = datas.Sum(x => x.TotalPendingCount);
worksheets.Cells["K" + k].Value = datas.Sum(x => x.TotalBlockCount);
using (ExcelRange Rng = worksheets.Cells[1, 7, totalRowsList, totalColumn.Length + 6])
{
Rng.Style.Border.Top.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Left.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Right.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
}
}
if (funcitonData != null)
{
foreach (var item in funValue)
{
worksheets.Cells["M" + l].Value = item.FunctionName;
worksheets.Cells["N" + l].Value = item.TotalCountTestCaseByTestRunId;
l++;
}
using (ExcelRange Rng = worksheets.Cells[1, 13, totalRowsForFuntion, totalColumn3.Length + 12])
{
Rng.Style.Border.Top.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Left.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Right.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
}
}
worksheets.Cells.AutoFitColumns();
result = package.GetAsByteArray();
return result;
}
}
catch (Exception ex)
{
throw new Exception($"Download failed : {ex.Message}");
}
}
}
var redarChart = worksheet.Drawings.AddRadarChart("RadarChart",
eRadarChartType.RadarMarkers);
redarChart.SetPosition(42, 0, 0, 0);
redarChart.SetSize(700, 300);
redarChart.Title.Text = "Function Map";
redarChart.Title.Font.Bold = true;
redarChart.Title.Font.Size = 12;
var serie = redarChart.Series.Add(worksheets.Cells[2, 14, funValue.Count + 1, 14], worksheets.Cells[2, 13, funValue.Count + 1, 13]);
serie.HeaderAddress = new ExcelAddress("'sheet'!N1");
redarChart.StyleManager.SetChartStyle(ePresetChartStyleMultiSeries.RadarChartStyle4);
redarChart.Fill.Color = System.Drawing.Color.Black;
redarChart.Legend.Position = eLegendPosition.TopRight;
//If you want to apply custom styling do that after setting the chart style so its not overwritten.
redarChart.Legend.Effect.SetPresetShadow(ePresetExcelShadowType.OuterTopLeft);
var radarSeries = (ExcelRadarChartSerie)serie;
radarSeries.Marker.Size = 5;
I'm converting my code for specific models to a generic (all models will be accepted) version so I'm converting my label border but I can't access data in model because of I was accessing them like this:
worksheet.Cells["A" + index].Value = temp[i - 2].CarID.ToString();
but now I converted this access to something like this:
worksheet.Cells[L + index].Value = temp[i - 2].names[j].ToString();
but it's not working. I understand first one accesses object values but second one tries to access different one so how can I access this object values? I'm past full code for this function can you give me some idea about this situation? Thanks for help
public void EEPCreateExcelGeneric(ReportRange reportRange)
{
using (ExcelPackage excel = new ExcelPackage())
{
// var temp = db.Database.SqlQuery<CarsTrxViewModel>(SqlCars.CarsTrxByID()).ToList();
var temp = db.Cars.ToList();
Cars cars = new Cars();
// var properties = temp.GetType().GetProperties();
var names = new List<string>();
var properties = cars.GetType().GetProperties();
foreach (var item in properties)
{
var attribute = (DisplayNameAttribute)item.GetCustomAttribute(typeof(DisplayNameAttribute), true);
if (attribute != null)
{
names.Add(attribute.DisplayName);
}
else
{
names.Add(item.Name);
}
}
// System.Diagnostics.Debug.WriteLine(properties);
DateTime startdate = reportRange.StartDate;// ?? new DateTime(2000, 10, 10, 1, 1, 1, 1);
DateTime enddate = reportRange.EndDate;// ?? DateTime.Now;
DateTime now = DateTime.Now;
string date = now.ToShortDateString();
string time = now.ToLongTimeString();
date = date + "-" + time;
// modeli çekerken db de temizlersek çok daha hızlı olur
foreach (var item in temp.ToList())
{
if (item.CreateDate < startdate || item.CreateDate > enddate)
{
temp.Remove(item);
}
}
int RowRange = temp.Count();
string name = "Report_";
date = date.Replace(" ", "_");
date = date.Replace(",", "_");
date = date.Replace(":", "-");
date = date.Replace("/", "_");
string sonu = ".xls";
date += sonu;
name += date;
ExcelRecords m = new ExcelRecords();
m.IsExist = false;
m.CreateDate = now;
m.EndDate = enddate;
m.StartDate = startdate;
m.GuidName = name;
db.ExcelRecords.Add(m);
db.SaveChanges();
excel.Workbook.Worksheets.Add("Worksheet1");
var worksheet = excel.Workbook.Worksheets["worksheet1"];
//worksheet.Cells["A1"].Value = "CarID";
//worksheet.Cells["B1"].Value = "CarBrand";
//worksheet.Cells["C1"].Value = "CarModel";
//worksheet.Cells["D1"].Value = "CreateDate";
//worksheet.Cells["A1"].Style.Font.Bold = true;
//worksheet.Cells["B1"].Style.Font.Bold = true;
//worksheet.Cells["C1"].Style.Font.Bold = true;
//worksheet.Cells["D1"].Style.Font.Bold = true;
for (int i = 0; i < names.Count(); i++)
{
string L = (Convert.ToChar(65+i)).ToString();
L += "1";
System.Diagnostics.Debug.WriteLine(L);
worksheet.Cells[L].Value = names[i];
worksheet.Cells[L].Style.Font.Bold = true;
}
for (int i = 2; i < (RowRange + 2); i++)
{
/*
string L = (Convert.ToChar(63 + i)).ToString();
string index = i.ToString();
worksheet.Cells[L + index].Value = temp[i - 2].CarID.ToString();
worksheet.Cells[L + index].Value = temp[i - 2].CarBrand.ToString();
worksheet.Cells[L + index].Value = temp[i - 2].CarModel.ToString();
worksheet.Cells[L + index].Value = temp[i - 2].CreateDate.ToString();
*/
string index = i.ToString();
for (int j = 0; j < names.Count; j++)
{
string L = (Convert.ToChar(65 + j)).ToString();
worksheet.Cells[L + index].Value = temp[i - 2].names[j].ToString();//<=
// its not working what is right way for doing this
}
worksheet.Cells["A" + index].Value = temp[i - 2].CarID.ToString();
worksheet.Cells["B" + index].Value = temp[i - 2].CarBrand.ToString();
worksheet.Cells["C" + index].Value = temp[i - 2].CarModel.ToString();
worksheet.Cells["D" + index].Value = temp[i - 2].CreateDate.ToString();
}
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
string path = Path.Combine(Server.MapPath("~/"), ("Reports\\" + name));
FileInfo excelFile = new FileInfo(path);
excel.SaveAs(excelFile);
var bull = db.ExcelRecords.SingleOrDefault(b => b.GuidName == name);
if (bull != null)
{
bull.IsExist = true;
db.SaveChanges();
}
}
}
I have a list of group box controls and i need to display only few questions in the flow layout panel but it is not displaying properly(width and height reduced) but if I add that controls to the form it is displaying properly
here is my code. please help me how to get back from this problem
code of flow layout panel(displyQues)
private void getQuestions(int quesid)
{
int j = 1;
for (int i = quesid; i <= lstgrpques.Count; i++)
{
displyQues.Location = new Point(15, 30);
displyQues.Show();
displyQues.Size = new System.Drawing.Size(1218, 620);
displyQues.AutoScroll = true;
lstgrpques[i - 1].Show();
displyQues.WrapContents = false;
displyQues.Controls.Add(lstgrpques[i - 1]);
displyQues.FlowDirection = FlowDirection.TopDown;
qstnId++;
j++;
if (j == 5)
{
break;
}
}
}
code of group box
foreach (var question in questions)
{
int QustTxtHght = 0;
GroupBox QuesAnsoptn = new GroupBox();
QuesAnsoptn.Hide();
QuesAnsoptn.AutoSize = true;
QuesAnsoptn.Width = 820;
QuesAnsoptn.Location = new Point(15, QustHgt);
var quest = question.Attribute("ques").Value.Trim();
if (quest.Contains('{'))
{
quest = GetFormatCode(quest);
QustTxtHght = quest.Length +40;
}
else
QustTxtHght = 15;
QuesAnsoptn.Text = question.Attribute("id").Value + ". " + quest;
QuesAnsoptn.Font = new Font("Microsoft Sans Serif", 10);
var options = question.Descendants("option");
var optHgt = 0;
foreach (var option in options)
{
RadioButton rdbtn = new RadioButton();
rdbtn.AutoSize = true;
rdbtn.Location = new Point(20, QustTxtHght + optHgt + 10);
rdbtn.Name = k.ToString();
lstRdOptns.Add(rdbtn);
rdbtn.Font = new Font("Microsoft Sans Serif", 10);
var opt = option.Value;
var loc = 0;
if (opt.Contains('{'))
{
opt = GetFormatCode(opt);
loc = opt.Length + 40;
}
else { loc = rdbtn.Size.Height; }
rdbtn.Text = opt;
optHgt = loc + optHgt;
QuesAnsoptn.Controls.Add(rdbtn);
}
k++;
this.Controls.Add(QuesAnsoptn);
QustHgt = QuesAnsoptn.Size.Height + QustHgt + 20;
QuesAnsoptn.Size = new System.Drawing.Size(820,QuesAnsoptn.Size.Height);
lstgrpques.Add(QuesAnsoptn);
}
for (int t = 0; t < ARF.Rows.Count; t += 1)
{
Chart1.Series[t].ChartType = SeriesChartType.Column;
Chart1.Series[t].BorderWidth = 2;
Chart1.Series[t].ToolTip = "(#VALX,#VALY)";
Chart1.ChartAreas["ChartArea1" + t.ToString()].AxisX.Title = "Learning Domains";
Chart1.ChartAreas["ChartArea1" + t.ToString()].AxisY.Title = "Covered";
Chart1.Legends.Add("Legend1" + t.ToString());
Chart1.Legends["Legend1" + t.ToString()].Enabled = false;
// Chart1.Legends["Legend1" + t.ToString()].Docking = Docking.Bottom;
Chart1.Legends["Legend1" + t.ToString()].Alignment = System.Drawing.StringAlignment.Center;
Chart1.Legends["Legend1" + t.ToString()].DockedToChartArea = "ChartArea1" + t.ToString();
// Chart1.Legends["Legend1" + t.ToString()].IsDockedInsideChartArea = false;
Random random = new Random();
foreach (var item in Graph.Series[0].Points)
{
System.Drawing.Color c = System.Drawing.Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
item.Color = c;
}
Chart1.Series[t]["PointWidth"] = "0.2";
Chart1.Series[t]["BarLabelStyle"] = "Center";
Chart1.Series[t]["PixelPointDepth"] = "99";
Chart1.Series[t]["DrawingStyle"] = "Cylinder";
}
for (int i = 0; i < 5; i++)
{
GridView gv = new GridView();
gv.DataSource = ds;
ph.Controls.Add(gv);
}
This is code to creating 5 charts, i want 5 charts with 5 tables of Grid View data together in 1 shot. can you please help me to do...i have tried but graphs are coming and grids are not visible.
If your using web application you can use google chart:
You can refer this link:
https://developers.google.com/chart/interactive/docs/gallery/controls