Пример #1
0
        public void ShouldSerialize()
        {
            var model = PxExtend.PxExtend.CreatePxModel("TestFiles\\BE0101A1.px");

            var ser = new XlsxSerializer();

            var stream = new MemoryStream();

            try
            {
                ser.Serialize(model, stream);

                MemoryStream destination = new MemoryStream();

                stream.CopyTo(destination);

                string actual = Encoding.UTF8.GetString(stream.ToArray());

                Assert.IsTrue(actual.Length >= 1);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
        //#start_publishing
        protected override void Test(Stream target)
        {
            var model = new List <QuestionSheetItem>
            {
                new QuestionSheetItem
                {
                    Question = "Does XlsSerializer support custom value converters?",
                    Answer   = true
                },
                new QuestionSheetItem
                {
                    Question = "Is it complicated?",
                    Answer   = false
                },
                new QuestionSheetItem
                {
                    Question = "Is there any comparable library?",
                    Answer   = null
                }
            };

            var serializer = new XlsxSerializer(new XlsxSerializerSettings(new CustomBoolTypeConverter()));

            serializer.Serialize(model, target);

            var deserialized = serializer.Deserialize <List <QuestionSheetItem> >(target);

            Assert.Equal(model, deserialized, CompareItems <QuestionSheetItem>((a, b) =>
            {
                Assert.Equal(a.Question, b.Question);
                Assert.Equal(a.Answer, b.Answer);

                return(true);
            }));
        }
Пример #3
0
        public override void SerializeAndStream()
        {
            //            Using stream As IO.MemoryStream = New IO.MemoryStream()
            //    Dim excelSerializer As New ExcelFileSerializer

            //    If Me.SelectedFormat.Equals(Plugins.FileFormats.XLS_DOUBLE_COLUMN) Then
            //        excelSerializer.DoubleColumn = DoubleColumnType.AlwaysDoubleColumns
            //    Else
            //        'Get doublecolumn from application setting
            //        excelSerializer.DoubleColumn = Settings.Files.DoubleColumnFile
            //    End If

            //    'Get information level from application setting
            //    excelSerializer.InformationLevel = Settings.Files.CompleteInfoFile
            //    'End If

            //    excelSerializer.Serialize(PaxiomManager.PaxiomModel, stream)
            //    StreamFile(stream, Me.SelectedFileType.MimeType, Me.SelectedFileType.FileExtension)
            //End Using

            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                PCAxis.Excel.XlsxSerializer ser;
                ser = new XlsxSerializer();

                if (this.SelectedFormat.Equals("FileTypeExcelXDoubleColumn"))
                {
                    ser.DoubleColumn = DoubleColumnType.AlwaysDoubleColumns;
                }
                else
                {
                    //Get doublecolumn from application setting
                    ser.DoubleColumn = Settings.Files.DoubleColumnFile;
                }

                //    'Get information level from application setting
                ser.InformationLevel = Settings.Files.CompleteInfoFile;


                ser.Serialize(PaxiomManager.PaxiomModel, stream);
                StreamFile(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx");
            }
        }