|
![]() |
#1 |
Участник
|
Цитата:
Я сам такое не делал. Хотя тут все аналогично как в моем примере с кафкой. Что-то вопрос популярен. Спрашивают его повторно в личке другие люди. Мой коллега делал. С его разрешения публикую его вариант X++: protected void insertImage_inCell( Filename _fileName , int _posX , int _posY , int64 _posXOffcet , int64 _posYOffcet , int64 _width , int64 _height ) { #define.EMU_per_pixel(9525)//EMU per pixel(approximately) DocumentFormat.OpenXml.Packaging.ImagePart imagePart; DocumentFormat.OpenXml.Drawing.Spreadsheet.ShapeProperties shapeProperties; DocumentFormat.OpenXml.Drawing.Spreadsheet.NonVisualPictureProperties nonVisualPictureProperties; DocumentFormat.OpenXml.Drawing.Spreadsheet.NonVisualDrawingProperties nonVisualDrawingProperties; DocumentFormat.OpenXml.Drawing.Spreadsheet.BlipFill blipFill; DocumentFormat.OpenXml.Drawing.Spreadsheet.Picture picture; DocumentFormat.OpenXml.Drawing.Spreadsheet.TwoCellAnchor twoCellAnchor; DocumentFormat.OpenXml.Drawing.Stretch stretch; DocumentFormat.OpenXml.Drawing.Blip blip; DocumentFormat.OpenXml.Drawing.Transform2D transform2D; DocumentFormat.OpenXml.Drawing.Extents extents; DocumentFormat.OpenXml.Drawing.PresetGeometry presetGeometry; System.IO.FileStream fileStream; DocumentFormat.OpenXml.Drawing.Spreadsheet.FromMarker fromMarker; DocumentFormat.OpenXml.Drawing.Spreadsheet.ToMarker toMarker; void clearNet() { imagePart = null; shapeProperties = null; nonVisualPictureProperties = null; nonVisualDrawingProperties = null; blipFill = null; picture = null; twoCellAnchor = null; stretch = null; blip = null; transform2D = null; extents = null; presetGeometry = null; fromMarker = null; toMarker = null; } picId += picId ? 1000 : 1; //Id начинаем с 1000, на случай, если в книге уже есть картинки imagePart = drawingsPart.AddImagePart(DocumentFormat.OpenXml.Packaging.ImagePartType::Png); fileStream = new System.IO.FileStream(_fileName, System.IO.FileMode::Open); imagePart.FeedData(fileStream); fileStream.Close(); fileStream.Dispose(); fileStream = null; blip = new DocumentFormat.OpenXml.Drawing.Blip(); blip.set_Embed(new DocumentFormat.OpenXml.StringValue(drawingsPart.GetIdOfPart(imagePart))); blipFill = new DocumentFormat.OpenXml.Drawing.Spreadsheet.BlipFill(); blipFill.set_Blip(blip); blipFill.set_SourceRectangle(new DocumentFormat.OpenXml.Drawing.SourceRectangle()); stretch = new DocumentFormat.OpenXml.Drawing.Stretch(); stretch.set_FillRectangle(new DocumentFormat.OpenXml.Drawing.FillRectangle()); OXML_RU::appendChild(blipFill, stretch); extents = new DocumentFormat.OpenXml.Drawing.Extents(); extents.set_Cx(new DocumentFormat.OpenXml.Int64Value(_width)); extents.set_Cy(new DocumentFormat.OpenXml.Int64Value(_height)); transform2D = new DocumentFormat.OpenXml.Drawing.Transform2D(); transform2D.set_Extents(extents); shapeProperties = new DocumentFormat.OpenXml.Drawing.Spreadsheet.ShapeProperties(); shapeProperties.set_BlackWhiteMode(OXMLExp::getEnumValue(DocumentFormat.OpenXml.Drawing.BlackWhiteModeValues::Auto)); shapeProperties.set_Transform2D(transform2D); Последний раз редактировалось Logger; 04.09.2025 в 23:10. Причина: не влезло сообщение - пришлось разбить на несколько |
|
|
За это сообщение автора поблагодарили: raz (10). |
Теги |
.net, ado, generic, net |
|
|