I am using the following code to add a comment :
ws.Cell("A5").Comment.SetVisible().AddText("sample");
ws.PageSetup.SetShowComments(XLShowCommentsValues.AsDisplayed);
When I comment out the following code, which adds an image to the excel document, then the comment works. But with this code uncommented, the below error occurs:
XLPicture pic = new XLPicture
{
NoChangeAspect = true,
NoMove = true,
NoResize = true,
ImageStream = memo,
Name = "Export Image",
PaddingX = 12,
PaddingY = 18
};
XLMarker fMark = new XLMarker { ColumnId = 1, RowId = 1 };
pic.AddMarker(fMark);
workSheet.AddPicture(pic);
Error is :
Related
So I am working to add the freeze pane in excel using openxml sdk and for that I am using the following code
SheetView sheetView1 = new() { TabSelected = true, WorkbookViewId = (UInt32Value)0U };
Pane pane1 = new()
{
HorizontalSplit = 1,
VerticalSplit = 1,
TopLeftCell = "B2",
ActivePane = PaneValues.TopRight,
State = PaneStateValues.Frozen
};
And this code works fine, but what I need to know is what the use of ActivePane present in 7th line as because if I remove that line it also works fine or if I change its value then it works the same.
And also there is one more piece of code added with the above code
Selection selection1 = new Selection()
{
Pane = PaneValues.TopRight,
ActiveCell = "B1",
SequenceOfReferences = new ListValue<StringValue>()
{
InnerText = "B1"
}
};
Selection selection2 = new Selection()
{
Pane = PaneValues.BottomLeft,
ActiveCell = "A3",
SequenceOfReferences = new ListValue<StringValue>()
{
InnerText = "A3"
}
};
Selection selection3 = new Selection()
{
Pane = PaneValues.BottomRight,
ActiveCell = "B3",
SequenceOfReferences = new ListValue<StringValue>()
{
InnerText = "B3"
}
};
And this code if I remove it also works fine.
So my question is can you tell me what is the use of ActivePane, the whole Selection Class and if I remove them from my code what it can raise the error in future.
Thanks.
I am trying to make a TextBox locked by using OpenXML SDK. I've tried this method but the TextBox NoTextEdit is not working.
public DocumentFormat.OpenXml.Presentation.Shape GenerateShape(string StrText)
{
DocumentFormat.OpenXml.Presentation.Shape shape1 = new DocumentFormat.OpenXml.Presentation.Shape();
DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties nonVisualShapeProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties();
DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties nonVisualDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = "ID",Hidden=true ,Description="Do not Remove" ,MCAttributes=null };
DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties();
Drawing.ShapeLocks shapeLocks1 = new Drawing.ShapeLocks() { NoTextEdit = true, NoGrouping = true,NoMove=true,NoSelection=true,NoEditPoints=true ,NoAdjustHandles=true ,NoRotation=true,NoChangeArrowheads=true,NoChangeAspect=true,NoChangeShapeType=true,NoResize=true};
nonVisualShapeDrawingProperties1.Append(shapeLocks1);
ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();
PlaceholderShape placeholderShape1 = new PlaceholderShape() { Type = PlaceholderValues.SubTitle, Index = (UInt32Value)1U };
applicationNonVisualDrawingProperties1.Append(placeholderShape1);
nonVisualShapeProperties1.Append(nonVisualDrawingProperties1);
nonVisualShapeProperties1.Append(nonVisualShapeDrawingProperties1);
nonVisualShapeProperties1.Append(applicationNonVisualDrawingProperties1);
DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties1 = new DocumentFormat.OpenXml.Presentation.ShapeProperties();
DocumentFormat.OpenXml.Presentation.TextBody textBody1 = new DocumentFormat.OpenXml.Presentation.TextBody();
Drawing.BodyProperties bodyProperties1 = new Drawing.BodyProperties();
Drawing.ListStyle listStyle1 = new Drawing.ListStyle();
Drawing.TextShape shp = new Drawing.TextShape();
Drawing.Paragraph paragraph1 = new Drawing.Paragraph();
Drawing.EndParagraphRunProperties endParagraphRunProperties1 = new Drawing.EndParagraphRunProperties() { Language = "en-US" ,Dirty=false };
paragraph1.Append(GenerateRun(StrText));
paragraph1.Append(endParagraphRunProperties1);
textBody1.Append(bodyProperties1);
textBody1.Append(listStyle1);
textBody1.Append(paragraph1);
shape1.Append(nonVisualShapeProperties1);
shape1.Append(shapeProperties1);
shape1.Append(textBody1);
return shape1;
}
public Drawing.Run GenerateRun(string StrText)
{
Drawing.Run run1 = new Drawing.Run();
Drawing.RunProperties runProperties1 = new Drawing.RunProperties() { Language = "en-US", Dirty = false };
runProperties1.SetAttribute(new OpenXmlAttribute("", "smtClean", "", "0"));
Drawing.Text text1 = new Drawing.Text();
text1.Text = StrText;
Drawing.SolidFill solidFill2 = new Drawing.SolidFill();
Drawing.SchemeColor schemeColor = new Drawing.SchemeColor();
string y = System.Drawing.Color.Transparent.ToArgb().ToString("X");
Drawing.RgbColorModelHex rgbColorModelHex2 = new Drawing.RgbColorModelHex() { Val = "FFFFFF" };//Set Font-Color to Blue (Hex "0070C0").
solidFill2.Append(rgbColorModelHex2);
runProperties1.Append(solidFill2);
Color color = new Color() { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" };
run1.Append(runProperties1);
run1.Append(text1);
return run1;
}
Everything works fine except editing. Still the user can edit the TextBox values by double clicking it. How can I avoid this ?
Is there any permanent solution to prevent editing ? Please help me to find a better solution.
Thanks in advance
By researching and communications with the MVP team I've pointed out that there is no way to Protect the TextBox from editing.
As Cindy Meister mentioned in the comments,
Are you able to do it in the PowerPoint application user interface? If not, then Open XML cannot do it... If yes, you can.
If you do not want to text to be changed , Just change it as image then lock that by using NoSelection=true/1 and NoMove=true/1 properties. If you enable these properties the user can't either delete nor change it's position.
For your ref: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_powerpoint-mso_windows8-mso_2016/shape-lock-is-not-working/c1705b55-d2aa-4adb-b538-574ed2fc8eca?tm=1579265435636&page=1&rtAction=1579495439869
I have a simple C# windows forms app. What I am trying to accomplish is modify the Default Root Object of one of my Cloud front Distributions. I can't seem to find any related articles that describes how this is accomplished. Please help
After alot of trial and error Here's the C# code to update an AWS cloud front distribution. You will need AWS's new modularized assemblies. AWSSKD.Core v3 & AWSSDK.Cloudfront.
First you need to get the current Distribution for 2 reasons. Mostly for validation you'll need to grab the Etag and Caller Reference. Etag to var and Caller Reference to string.
var client2 = new AmazonCloudFrontClient();
var tag = client2.GetDistributionConfig(new GetDistributionConfigRequest
{
Id = "YOURDISTID"
}).ETag;
string cf = client2.GetDistributionConfig(new GetDistributionConfigRequest
{
Id = "YOURDISTID"
}).DistributionConfig.CallerReference;
client2.Dispose();
Next you will need to make a update to the distribution. What I have below is the minimally required to update a distribution (Pretty much Everything you see in the AWS console when editing a distribution.
Take notice of where tag variable and cf string are used. If the Etag's do not match you will get 400 bad request back.
var client = new AmazonCloudFrontClient();
client.UpdateDistribution(new UpdateDistributionRequest
{
Id = "YOURDISTID",
DistributionConfig = new DistributionConfig
{
WebACLId = "",
HttpVersion = "http2",
IsIPV6Enabled = true,
DefaultRootObject = "maintenance.html",
CacheBehaviors = new CacheBehaviors {
Quantity = 0,
},
Restrictions = new Restrictions {
GeoRestriction = new GeoRestriction
{
Quantity = 0,
RestrictionType = "none"
}
},
CustomErrorResponses = new CustomErrorResponses {
Quantity = 0
},
ViewerCertificate = new ViewerCertificate {
SSLSupportMethod = "sni-only",
ACMCertificateArn = "YOUR_IMPORTED_CERT_ARN",
MinimumProtocolVersion = "TLSv1.1_2016"
},
Enabled = true,
Comment = "Maintenance",
Origins = new Origins
{
Items = new List<Origin>() {
new Origin(){Id = "S3-example.example.com", DomainName = "example.example.com.s3.amazonaws.com", S3OriginConfig = new S3OriginConfig(){ OriginAccessIdentity = "" }, OriginPath = "", CustomHeaders = new CustomHeaders{ Quantity = 0 } }
},
Quantity = 1
},
Logging = new Amazon.CloudFront.Model.LoggingConfig
{
Bucket = "example.example.com.s3.amazonaws.com",
IncludeCookies = false,
Enabled = false,
Prefix = ""
},
PriceClass = "PriceClass_All",
Aliases = new Aliases
{
Quantity = 1,
Items = list
},
CallerReference = cf,
DefaultCacheBehavior = new DefaultCacheBehavior
{
ForwardedValues = new ForwardedValues
{
QueryString = false,
QueryStringCacheKeys = new QueryStringCacheKeys {
Quantity = 0
},
Headers = new Headers {
Quantity = 0
},
Cookies = new CookiePreference
{
Forward = "none"
}
},
AllowedMethods = new AllowedMethods {
Quantity = 2,
Items = httpmeth,
CachedMethods = new CachedMethods
{
Quantity = 2,
Items = httpmeth
}
},
DefaultTTL = 86400,
Compress = false,
MaxTTL = 31536000,
TargetOriginId = "S3-example.example.com",
LambdaFunctionAssociations = new LambdaFunctionAssociations {
Quantity = 0
},
ViewerProtocolPolicy = "allow-all",
MinTTL = 0,
SmoothStreaming = false,
TrustedSigners = new TrustedSigners
{
Enabled = false,
Quantity = 0,
},
}
},
IfMatch = tag
});
client.Dispose();
If you have issues with ACMCertificationARN not being found in the reference Assembly chances are you are using the old v2 AWSSDK. Remove\Uninstall it. Get the latest Nuget Package for AWSSKD.Core & AWSSDK.CloudFront
Nuget Package Manager Console Install:
Install-Package AWSSDK.Core -Version 3.3.21.17
Install-Package AWSSDK.CloudFront -Version 3.3.6.3
I'm using asp.net for generating pdf file. In pdf i must show plot. I decided using oxyplot with exporting it in png and inserting in pdf. The documentation says using PlotModel, filling it with series and axes and simply export by using PngExporting object. But when I'm trying generate it, nothing is presented except the axes.
The code I'm using:
var _plotModel = new OxyPlot.PlotModel()
{
PlotAreaBorderColor = OxyPlot.OxyColors.Transparent,
LegendBorder = OxyPlot.OxyColors.Transparent,
TitleToolTip = "Temperature",
Culture = new System.Globalization.CultureInfo("ru-Ru"),
Series =
{
new OxyPlot.Series.LineSeries()
{
ItemsSource = new List<SimplePointModel>
{
new SimplePointModel { Date = DateTime.Now, Temperature = 36.6f },
new SimplePointModel { Date = DateTime.Now.AddDays(1), Temperature = 42.6f },
new SimplePointModel { Date = DateTime.Now.AddDays(2), Temperature = 48.6f },
},
MarkerFill = OxyPlot.OxyColor.Parse("#A9CF9C"),
MarkerType = OxyPlot.MarkerType.Circle,
MarkerSize = item.ListSegments[0].Count() == 1 ? 2 : 1,
DataFieldX = "Date",
DataFieldY = "Temperature",
XAxisKey = "Date",
YAxisKey = "Temperature",
Color = OxyPlot.OxyColor.Parse("#A9CF9C"),
}
},
Axes =
{
new OxyPlot.Axes.DateTimeAxis()
{
Position = OxyPlot.Axes.AxisPosition.Bottom,
Key = "Date",
ToolTip = "Temperature",
AbsoluteMinimum = OxyPlot.Axes.Axis.ToDouble(DateTime.Now.Date),
AbsoluteMaximum = OxyPlot.Axes.Axis.ToDouble(DateTime.Now.AddDays(10000))
},
new OxyPlot.Axes.LinearAxis()
{
Position = OxyPlot.Axes.AxisPosition.Left,
Key = "Temperature",
ToolTip = "Temperature",
IsZoomEnabled = false,
IsPanEnabled = false,
}
}
};
using (var stream = System.IO.File.Create(Path.Combine(folder, "temp.png")))
{
PngExporter.Export(_plotModel, stream, 800, 400, OxyPlot.OxyColors.Transparent);
}
What can I do?
I found solution: we must load data to Points list parameter in Series object instead of ItemSource parameter. ItemSource parameter used in mobile version of library.
I'm using TuesPechkin to convert HTML to PDF and I'm specifying the URL of an HTML file that should appear as the footer on each page, however it doesn't render the footer. As a test, I even tried setting the LeftText to something and that doesn't render either.
My code is as below:
Dim FooterURL As String = "http://localhost:60699/testfooter.html"
Dim globalSettings As New TuesPechkin.GlobalSettings With {.PaperSize = PaperKind.A4,
.DocumentTitle = DocTitle,
.Margins = New TuesPechkin.MarginSettings With {.Unit = TuesPechkin.Unit.Millimeters, .Bottom = 20, .Left = 20, .Right = 20, .Top = 20},
.Copies = 1,
.ImageQuality = 100,
.ImageDPI = 300,
.ProduceOutline = True,
.PageOffset = 0,
.DPI = 1200,
.Orientation = TuesPechkin.GlobalSettings.PaperOrientation.Portrait}
Dim pdfdoc As New TuesPechkin.HtmlToPdfDocument
pdfdoc.Objects.Add(New TuesPechkin.ObjectSettings With {.HtmlText = strHTML,
.FooterSettings = New TuesPechkin.FooterSettings With {.HtmlUrl = FooterURL, .LeftText = "blah blah blah"},
.WebSettings = New TuesPechkin.WebSettings With {.LoadImages = True,
.PrintBackground = True,
.EnableJavascript = False}
})
Dim convertor As TuesPechkin.IPechkin = TuesPechkin.Factory.Create
Dim buf As Byte() = convertor.Convert(strHTML)
Return buf
This problem has been fixed in version 1.1.0, which has not been released yet.
See https://github.com/tuespetre/TuesPechkin/issues/46
You can pull the source from GitHub and build the current code yourself to fix your issue.
Edit: Should be fixed now, as of version 2.0.0.
https://github.com/tuespetre/TuesPechkin/releases