Esempio n. 1
0
        public void CellsOleObjectsPutWorksheetOleObjectTest()
        {
            // TODO uncomment below to test the method and replace null with proper value
            string name      = BOOK1;
            string sheetName = SHEET6;

            int?      upperLeftRow    = 1;
            int?      upperLeftColumn = 1;
            int?      height          = 100;
            int?      width           = 80;
            string    oleFile         = "OLEDoc.docx";
            string    imageFile       = "word.jpg";
            string    folder          = TEMPFOLDER;
            OleObject oleObject       = new OleObject();

            oleObject.UpperLeftColumn     = 1;
            oleObject.UpperLeftRow        = 1;
            oleObject.Width               = 80;
            oleObject.Height              = 100;
            oleObject.ImageSourceFullName = imageFile;
            oleObject.SourceFullName      = oleFile;
            oleObject = null;
            UpdateDataFile(instance, folder, name);
            UpdateDataFile(instance, folder, oleFile);
            UpdateDataFile(instance, folder, imageFile);
            var response = instance.CellsOleObjectsPutWorksheetOleObject(name, sheetName, oleObject, upperLeftRow, upperLeftColumn, height, width, folder + "\\" + oleFile, folder + "\\" + imageFile, folder);

            Assert.IsInstanceOf <OleObjectResponse>(response, "response is OleObjectResponse");
            Assert.AreEqual(response.Code, 200);
        }
        private string Get10Bytes(OleObject oleObject)
        {
            byte[] bytes = oleObject.Content;
            var    chunk = new byte[10];

            Array.Copy(bytes, chunk, 10);
            var builder = new StringBuilder();

            foreach (var b in chunk)
            {
                builder.Append(b + ", ");
            }

            builder.Remove(builder.Length - 3, 1);
            return(builder.ToString());
        }
        public static void Run()
        {
            // ExStart:ExtractEmbeddedObjects
            // The path to the documents directory.
            string    dataDir = RunExamples.GetDataDir_ModifyingCreatedProject();
            Project   project = new Project(dataDir + "Project1.mpp");
            OleObject ole     = project.OleObjects.ToList()[0];

            // we have to check this property because it can be null if the embedded object was created inside the ms project application Or, alternatively, you can use this check: if (ole.FileFormat == "Package")
            if (!string.IsNullOrEmpty(ole.FullPath))
            {
                using (FileStream fileStream = new FileStream(dataDir, FileMode.Create))
                    fileStream.Write(ole.Content, 0, ole.Content.Length);
            }
            // ExEnd:ExtractEmbeddedObjects
        }
Esempio n. 4
0
        public void CellsOleObjectsPostUpdateWorksheetOleObjectTest()
        {
            // TODO uncomment below to test the method and replace null with proper value
            string    name           = "Book1.xlsx";
            string    sheetName      = "SHEET6";
            int?      oleObjectIndex = 0;
            OleObject ole            = new OleObject();

            ole.Left   = 10;
            ole.Right  = 10;
            ole.Height = 90;
            ole.Width  = 78;
            string folder = null;

            new Config().UpdateDataFile(folder, name);
            var response = instance.CellsOleObjectsPostUpdateWorksheetOleObject(name, sheetName, oleObjectIndex, ole, folder);

            Console.WriteLine(response);
        }
Esempio n. 5
0
        private static (bool isSuccess, FileInfo file) TryGetFallbackImage(OleObject oleElement)
        {
            var slide = oleElement.Ancestors <Slide>().First();

            var slidePart = slide.SlidePart;
            var frame     = oleElement.Ancestors <GraphicFrame>().First();

            var frameGraphic = frame.Graphic.GraphicData;

            var fallback = frameGraphic.Descendants <DocumentFormat.OpenXml.AlternateContentFallback>().FirstOrDefault();

            if (fallback == null)
            {
                return(false, null);
            }

            var picture = fallback.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().FirstOrDefault();

            if (picture == null)
            {
                return(false, null);
            }

            var embed = picture.BlipFill.Blip.Embed.Value;

            var part = slidePart.GetPartById(embed);

            if (part is ImagePart imagePart)
            {
                if (imagePart.ContentType == "image/x-wmf" || imagePart.ContentType == "image/x-emf")
                {
                    var stream   = part.GetStream(FileMode.Open, FileAccess.Read);
                    var fileName = Path.GetFileName(imagePart.Uri.OriginalString);
                    var file     = Path.Combine(@"F:\lindexi", fileName);
                    File.WriteAllBytes(file, ReadAllBytes(stream));

                    return(true, new FileInfo(file));
                }
            }

            return(false, null);
        }
Esempio n. 6
0
        public void CellsOleObjectsPostUpdateWorksheetOleObjectTest()
        {
            // TODO uncomment below to test the method and replace null with proper value
            string    name           = BOOK1;
            string    sheetName      = SHEET6;
            int?      oleObjectIndex = 0;
            OleObject ole            = new OleObject();

            ole.Left   = 10;
            ole.Right  = 10;
            ole.Height = 90;
            ole.Width  = 78;
            string folder = TEMPFOLDER;

            UpdateDataFile(instance, folder, name);
            var response = instance.CellsOleObjectsPostUpdateWorksheetOleObject(name, sheetName, oleObjectIndex, ole, folder);

            Assert.IsInstanceOf <CellsCloudResponse>(response, "response is CellsCloudResponse");
            Assert.AreEqual(response.Code, 200);
        }
Esempio n. 7
0
        public void CellsOleObjectsPutWorksheetOleObjectTest()
        {
            // TODO uncomment below to test the method and replace null with proper value
            string    name            = "Book1.xlsx";
            string    sheetName       = "SHEET6";
            OleObject oleObject       = null;
            int?      upperLeftRow    = 1;
            int?      upperLeftColumn = 1;
            int?      height          = 100;
            int?      width           = 80;
            string    oleFile         = "OLEDoc.docx";
            string    imageFile       = "word.jpg";
            string    folder          = null;

            new Config().UpdateDataFile(folder, name);
            new Config().UpdateDataFile(folder, oleFile);
            new Config().UpdateDataFile(folder, imageFile);
            var response = instance.CellsOleObjectsPutWorksheetOleObject(name, sheetName, oleObject, upperLeftRow, upperLeftColumn, height, width, folder + "/" + oleFile, folder + "/" + imageFile, folder);

            Console.WriteLine(response);
        }
Esempio n. 8
0
        public static void Run()
        {
            // ExStart:GetSetClassIdentifierEmbedOleObject
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Load your sample workbook which contains embedded PowerPoint ole object
            Workbook wb = new Workbook(dataDir + "sample.xls");

            // Access its first worksheet
            Worksheet ws = wb.Worksheets[0];

            // Access first ole object inside the worksheet
            OleObject oleObj = ws.OleObjects[0];

            // Convert 16-bytes array into GUID
            Guid guid = new Guid(oleObj.ClassIdentifier);

            // Print the GUID
            Console.WriteLine(guid.ToString().ToUpper());
            // ExEnd:GetSetClassIdentifierEmbedOleObject
        }
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            // Load your sample workbook which contains embedded PowerPoint ole object
            Workbook wb = new Workbook(sourceDir + "sampleGetSetClassIdentifierEmbedOleObject.xls");

            // Access its first worksheet
            Worksheet ws = wb.Worksheets[0];

            // Access first ole object inside the worksheet
            OleObject oleObj = ws.OleObjects[0];

            // Convert 16-bytes array into GUID
            Guid guid = new Guid(oleObj.ClassIdentifier);

            // Print the GUID
            Console.WriteLine(guid.ToString().ToUpper());

            Console.WriteLine("GetSetClassIdentifierEmbedOleObject executed successfully.");
        }
Esempio n. 10
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            byte[] imageData = File.ReadAllBytes(sourceDir + "sampleInsertOleObject_WAVFile.jpg");

            // Define an array of bytes.
            byte[] objectData = File.ReadAllBytes(sourceDir + "sampleInsertOleObject_WAVFile.wav");

            // Instantiate a new Workbook.
            Workbook workbook = new Workbook();

            Worksheet sheet = workbook.Worksheets[0];

            // Add Ole Object
            int idx = sheet.OleObjects.Add(3, 3, 200, 220, imageData);

            OleObject ole = sheet.OleObjects[idx];

            ole.FileFormatType       = FileFormatType.Ole10Native;
            ole.ObjectData           = objectData;
            ole.ObjectSourceFullName = "sample.wav";
            ole.ProgID = "Packager Shell Object";

            Guid gu = new Guid("0003000c-0000-0000-c000-000000000046");

            ole.ClassIdentifier = gu.ToByteArray();

            // Save the excel file
            workbook.Save(outputDir + "outputInsertOleObject_WAVFile.xlsx");

            Console.WriteLine("InsertOleObject_WAVFile executed successfully.");
        }
Esempio n. 11
0
 public override Guid GetGuid()
 {
     return(OleObject.GetGuid());
 }