How can I apply conditional formatting in C++ MFC? - c++

https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2007/bb404903(v=office.12)?redirectedfrom=MSDN
Microsoft provides example codes in C# and Visual Basic.
For example C# code as follows.
ApplicationClass excelApplication = null;
Workbook newWorkbook = null;
Worksheet targetSheet = null;
ColorScale cfColorScale = null;
IconSetCondition cfIconSet = null;
string paramWorkbookPath = #"C:\Temp\Test.xlsx";
object paramMissing = Type.Missing;
excelApplication = new ApplicationClass();
newWorkbook = excelApplication.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
targetSheet = (Worksheet)(newWorkbook.Worksheets[1]);
targetSheet.Name = "Conditional Formatting";
// Fill cells A1:A10 with sample data.
targetSheet.get_Range("A1", paramMissing).set_Value(XlRangeValueDataType.xlRangeValueDefault, 1);
targetSheet.get_Range("A2", paramMissing).set_Value(XlRangeValueDataType.xlRangeValueDefault, 2);
targetSheet.get_Range("A1:A2",
paramMissing).AutoFill(targetSheet.get_Range("A1:A10", paramMissing), XlAutoFillType.xlFillSeries);
// Create a two-color ColorScale object for the created sample data
// range.
cfColorScale = (ColorScale)(targetSheet.get_Range("A1:A10",
Type.Missing).FormatConditions.AddColorScale(2));
// Set the minimum threshold to red (0x000000FF) and maximum threshold
// to blue (0x00FF0000).
cfColorScale.ColorScaleCriteria[1].FormatColor.Color = 0x000000FF;
cfColorScale.ColorScaleCriteria[2].FormatColor.Color = 0x00FF0000;
How can we apply conditional formatting in C++ MFC?
range = ws.get_Range(COleVariant(_T("A1"), COleVariant(_T("A10")));
CFormatCondition fc;
fc = range.get_FormatConditions();

Related

How to show all tooltip Text where line series circle bullets intersect Amcharts 4?

I am using a Amcharts4 Line series with valueX and valueY instead of categoryX.
Currently I am able to see the tooltip on a hover of bullet/bubble but I also want to see the tooltip of all bullets if they are intersecting and overlapping with each other.
It shows the tooltip if i hover on a single bullet/bubble but if you see the red and green line intersecting each other, it shows the tooltip of green bullet/bubble only, not the other which is hidden at its back.
Click here to see Line Series graph with ValueX and ValueY
This is my code where I am having 3 series and setup a tooltip for each bullet :
let series1 = chart.series.push(new am4charts.LineSeries());
series1.cursorTooltipEnabled = true;
series1.showTooltipOn = 'hover';
series1.dataFields.valueY = "compressorCap";
// series1.dataFields.categoryX = "evapDegC"; // If X-Axis is Category Axis
series1.dataFields.valueX = "evapDegC"; // If X-Axis is Value Axis
series1.name = "Compressor capacity";
let series1toolTip = series1.bullets.push(new am4charts.CircleBullet());
series1toolTip.tooltipText = "{name} in {valueX}°C => {valueY}";
series1.tooltip.getFillFromObject = false;
series1.tooltip.background.fill = am4core.color("#b9a9e6");
series1.legendSettings.valueText = "{valueY}";
series1.visible = false;
series1.stroke = am4core.color("#b9a9e6");
let series2 = chart.series.push(new am4charts.LineSeries());
series2.cursorTooltipEnabled = true;
series2.showTooltipOn = 'hover';
series2.dataFields.valueY = "evapCoilCap";
// series2.dataFields.categoryX = "evapDegC"; // If X-Axis is Category Axis
series2.dataFields.valueX = "evapDegC"; // If X-Axis is Value Axis
series2.name = 'Evaporator coil capacity';
let series2toolTip = series2.bullets.push(new am4charts.CircleBullet());
series2toolTip.tooltipText = "{name} in {valueX}°C => {valueY}";
series2.tooltip.getFillFromObject = false;
series2.tooltip.background.fill = am4core.color("red");
series2.legendSettings.valueText = "{valueY}";
series2.stroke = am4core.color("red");
let series3 = chart.series.push(new am4charts.LineSeries());
series3.cursorTooltipEnabled = true;
series3.showTooltipOn = 'hover';
series3.dataFields.valueY = "evapCoilSensibleCap";
// series3.dataFields.categoryX = "evapDegC"; // If X-Axis is Category Axis
series3.dataFields.valueX = "evapDegC"; // If X-Axis is Value Axis
series3.name = 'Evaporator sensible cooling capacity ';
let series3toolTip = series3.bullets.push(new am4charts.CircleBullet());
series3toolTip.tooltipText = "{name} in {valueX}°C => {valueY}";
series3.tooltip.getFillFromObject = false;
series3.tooltip.background.fill = am4core.color("#13bb37");
series3.legendSettings.valueText = "{valueY}";
series3.stroke = am4core.color("#13bb37");
// Add chart cursor
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "zoomY";
In order to display multiple tooltips, you need to set tooltipText directly on series, not on a bullet.
series.tooltipText = "{name} in {valueX}°C => {valueY}";
That's the first step, though. Since you are using all-ValueAxis scenario, you will also need to apply a workaround as stated in this tutorial.
am4charts.ValueAxis.prototype.getSeriesDataItem = function(series, position) {
var key = this.axisFieldName + this.axisLetter;
var value = this.positionToValue(position);
var dataItem = series.dataItems.getIndex(series.dataItems.findClosestIndex(value, function(x) {
return x[key] ? x[key] : undefined;
}, "any"));
return dataItem;
}
This will enable multi-cursors across all charts.
Or if you want to enable for just for a single axis:
valueAxisX.getSeriesDataItem = function(series, position) {
var key = this.axisFieldName + this.axisLetter;
var value = this.positionToValue(position);
var dataItem = series.dataItems.getIndex(series.dataItems.findClosestIndex(value, function(x) {
return x[key] ? x[key] : undefined;
}, "any"));
return dataItem;
}
If you don't want to show all tooltips for all the series all the time, you can set cursor's maxTooltipDistance to a small number so that multiple tooltips are shown only if target items are closely packged together, e.g.:
chart.cursor.maxTooltipDistance = 10;

How to Add Image/Shape with chart data label in ASPOSE Slide

Can we add any shape/image with chart data labels in ASPOSE .I need to show one arrow with different colors according to certain values with each data labels in the chart. i am using ASPOSE to generate my ppt. Or there is any way to find the data label positions in ASPOSE.
I have observed your requirements and like to share that MS PowerPoint supports LineWithMarker chart that can display different predefined or custom marker symbols(in the form of image) for different series data points. Please try using following sample code for possible options using Aspose.Slides and MSO charts.
public static void TestScatter()
{
var location = System.Reflection.Assembly.GetExecutingAssembly().Location;
//Open a presentation
Presentation pres = new Presentation();
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.StackedLineWithMarkers, 10, 10, 400, 400);
//populating cycle
var serie = chart.ChartData.Series[0];
var wbk = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series.RemoveAt(1);
chart.ChartData.Series.RemoveAt(1);
serie.Marker.Format.Fill.FillType = FillType.Picture;
serie.Marker.Size = 20;
// Set the picture
System.Drawing.Image img = (System.Drawing.Image)new Bitmap(#"C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg");
IPPImage imgx = pres.Images.AddImage(img);
serie.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx;
//For individual data point
serie.DataPoints[0].Marker.Format.Fill.FillType = FillType.Solid;
serie.DataPoints[0].Marker.Format.Fill.SolidFillColor.Color = Color.Red;
serie.DataPoints[0].Marker.Size = 20;
serie.DataPoints[0].Marker.Symbol = MarkerStyleType.Triangle;
serie.DataPoints[0].Label.DataLabelFormat.ShowValue = true;
serie.DataPoints[1].Label.DataLabelFormat.ShowValue = true;
serie.DataPoints[2].Label.DataLabelFormat.ShowValue = true;
serie.DataPoints[3].Label.DataLabelFormat.ShowValue = true;
pres.Save(Path.Combine(Path.GetDirectoryName(location), "Result2.pptx"), SaveFormat.Pptx);
}
I am working as Support developer/ Evangelist at Aspose.
Many Thanks,
I have further observed your requirements and have observed that you have also posted the similar requirements in Aspose.Slides official support forum as well. Please try using following sample code on your end to serve the purpose.
public static void TestLineChart()
{
var location = System.Reflection.Assembly.GetExecutingAssembly().Location;
//Open a presentation
Presentation pres = new Presentation();
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.StackedLineWithMarkers, 10, 10, 400, 400);
//populating cycle
var serie = chart.ChartData.Series[0];
var wbk = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series.RemoveAt(1);
chart.ChartData.Series.RemoveAt(1);
serie.Marker.Format.Fill.FillType = FillType.Picture;
serie.Marker.Size = 20;
serie.Marker.Symbol = MarkerStyleType.Diamond;
serie.Marker.Format.Fill.FillType = FillType.Solid;
serie.Marker.Format.Fill.SolidFillColor.Color=Color.Orange;
serie.Marker.Format.Line.FillFormat.FillType = FillType.Solid;
serie.Marker.Format.Line.FillFormat.SolidFillColor.Color=Color.Red;
serie.Marker.Format.Line.Width=1.0F;
serie.Format.Line.Width = 3.0f;
serie.Format.Line.FillFormat.FillType=FillType.Solid;
serie.Format.Line.FillFormat.SolidFillColor.Color = Color.FromArgb(209,225,91) ;
for(int i=0;i<serie.DataPoints.Count;i++)
{
serie.DataPoints[i].Label.DataLabelFormat.ShowValue = true;
IDataLabel label=serie.Labels[i];
chart.ValidateChartLayout();
IAutoShape ashp=chart.UserShapes.Shapes.AddAutoShape(ShapeType.Triangle,chart.X + label.ActualX + 5, chart.Y + label.ActualY + 5, 20,20);
ashp.FillFormat.FillType = FillType.Solid;
ashp.LineFormat.FillFormat.FillType = FillType.NoFill;
if (i % 2 == 0)//even data points
{
ashp.FillFormat.SolidFillColor.Color = Color.Green;
}
else
{
ashp.Rotation = 180;
ashp.FillFormat.SolidFillColor.Color = Color.Red;
}
}
pres.Save(Path.Combine(Path.GetDirectoryName(location), "Result2.pptx"), Aspose.Slides.Export.SaveFormat.Pptx);
}
I am working as Support developer/ Evangelist at Aspose.
Many Thanks,

MFC open type font features in programming

The code below is part my function which prints out telephone number. The function works correctly with the selected font and size except for one small problem in the output.
cDrucker* drucker;
CFont fontText;
LOGFONT logFont;
Int links = 125;
::ZeroMemory(&logFont, sizeof(LOGFONT));
logFont.lfHeight = -MulDiv(9.5, drucker->printerDC.GetDeviceCaps(LOGPIXELSY), 72);
logFont.lfWidth = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = FW_NORMAL;
logFont.lfItalic = FALSE;
logFont.lfUnderline = FALSE;
logFont.lfStrikeOut = FALSE;
logFont.lfCharSet = ANSI_CHARSET;
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfClipPrecision = CLIP_DFA_DISABLE;
logFont.lfQuality = CLEARTYPE_QUALITY;
logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
strcpy_s(logFont.lfFaceName, "MetaOT-Book");
fontText.CreateFontIndirect(&logFont);
int y = 49 - 6 - 5;
drucker->printerDC.SelectObject(&fontText);
drucker->textOut("Telefon: (0123)456789", links, &y, false);
Output 1: The actual output that is printed by the function
output 2: The output I want.
The question is how i can avoid the alternative up and down pattern in output 1 and make it look like output 2 ?
I know this is how the font is suppose to print the number. it is by design in that way but in MS word using font options I can change it to my desired output.
as shown in the below picture.
I dont want to use another font So I was wondering if I could achieve the same using my program.
Font and Size:

Zed Camera - Get data in c++ with openCV

I used with Zed-Camera for get depth (https://www.stereolabs.com/).
I want to get the data in c++ (using the OpenCV library).
I took the code from here:
https://www.stereolabs.com/blog/index.php/2015/06/28/zed-with-opencv/
The code on the website is not working, because one line does not compile:
sl::zed::ERRCODE err = zed->init(sl::zed::MODE::PERFORMANCE, 0, true);
I get 2 errors:
initial value of reference to non-const must be an lvalue
too many arguments in function call.
I looked in the function, the function get:
ERRCODE init(InitParams &parameters);
I would appreciate your help
Yes as you can see the parameters was changed to InitParams.
sl::zed::InitParams params;
params.verbose = true;
sl::zed::ERRCODE err = camera->init(params);
You can do something similar to this.
m_pZed = new sl::Camera();
sl::InitParameters zedInit;
zedInit.camera_buffer_count_linux = 4;
zedInit.camera_disable_self_calib = false;
zedInit.camera_fps = m_zedFPS;
zedInit.camera_image_flip = m_bZedFlip;
zedInit.camera_linux_id = 0;
zedInit.camera_resolution = (sl::RESOLUTION) m_zedResolution;
zedInit.coordinate_system = sl::COORDINATE_SYSTEM::COORDINATE_SYSTEM_IMAGE;
zedInit.coordinate_units = sl::UNIT::UNIT_METER;
zedInit.depth_minimum_distance = m_zedMinDist;
zedInit.depth_mode = (sl::DEPTH_MODE) m_zedDepthMode;
zedInit.sdk_gpu_id = -1;
zedInit.sdk_verbose = true;
sl::ERROR_CODE err = m_pZed->open(zedInit);
if (err != sl::SUCCESS)
{
LOG(ERROR)<< "ZED Error code: " << sl::errorCode2str(err) << std::endl;
return false;
}
m_pZed->setConfidenceThreshold(m_zedConfidence);
m_pZed->setDepthMaxRangeValue((float) m_zedMaxDist);
// Set runtime parameters after opening the camera
m_zedRuntime.sensing_mode = (sl::SENSING_MODE) m_zedSenseMode;
m_zedRuntime.enable_depth = true;
m_zedRuntime.enable_point_cloud = false;
m_zedRuntime.move_point_cloud_to_world_frame = false;
// Create sl and cv Mat to get ZED left image and depth image
sl::Resolution zedImgSize = m_pZed->getResolution();
// Initialize color image and depth
m_width = zedImgSize.width;
m_height = zedImgSize.height;
m_centerH = m_width / 2;
m_centerV = m_height / 2;
// Best way of sharing sl::Mat and cv::Mat :
// Create a sl::Mat and then construct a cv::Mat using the ptr to sl::Mat data.
m_pzDepth = new sl::Mat(zedImgSize, sl::MAT_TYPE_32F_C1, sl::MEM_GPU);
m_gDepth = slMat2cvGpuMat(*m_pzDepth);
m_gDepth2 = GpuMat(m_gDepth.size(), m_gDepth.type());
More details can be found here( https://github.com/yankailab/OpenKAI/blob/master/src/Vision/_ZED.cpp )

How do I render a Dundas bar chart from most to least?

How does one order the bar chart series to render from most to least? Ordering the data before binding does not seem to help.
My code:
chart.Series.Add("port");
chart.Series["port"].Type = SeriesChartType.Bar;
chart.Series["port"]["PointWidth"] = "0.6";
chart.Series["port"]["BarLabelStyle"] = "Center";
chart.Series["port"].ShowLabelAsValue = true;
chart.Series["port"].Points.DataBind(myData, "Key", "Value", "Label=Value{p2}");
chart.Series["port"].BorderStyle = ChartDashStyle.Solid;
chart.Series["port"].BorderColor = Color.White;
chart.Series["port"].BorderWidth = 1;
chart.Series["port"].ShowLabelAsValue = true;
chart.Series["port"].Font = myfont;
chart.ChartAreas.Add("Default");
chart.ChartAreas["Default"].BackColor = Color.Transparent;
foreach (var axis in chart.ChartAreas["Default"].Axes)
{
axis.LabelStyle.Font = myfont;
axis.MajorGrid.Enabled = false;
}
chart.ChartAreas["Default"].AxisX.Interval = 1;
chart.ChartAreas["Default"].AxisY.LabelStyle.Format = "p0";
You need to call Sort() on the series, see http://msdn.microsoft.com/en-us/library/dd455394.aspx. So to sort the points from most to least you'd do
chart.Series["port"].Sort(PointSortOrder.Descending);
There are two other sort methods incase you need to sort by something other than the point value.