Set a binding programmatically between a component and a value from a list - silverlight-3.0

I'm developing a application in Silverlight 3 and I have a dynamic form, I generate this form from a list of attributes (key-value) I'd like to know, how can I set a binding between the component (CheckBox, TextBox, ...) and the value of the attribute?
This code is only the first approximation to the solution, no the definitive code:
int numeroFila = 0;
MainPage rootPage = ((App)Application.Current).RootVisual as MainPage;
rootPage.NuevoElementoWindowInstance.NuevoElementoInstance.ListadoAtributos.Children.Clear();
foreach (var atributo in ListaAtributos)
{
string tipoAtributo = ObtenerDefinicionAtributo(atributo.Key);
FrameworkElement campoDatos;
TextBlock bloqueTexto = new TextBlock();
bloqueTexto.Text = atributo.Key;
bloqueTexto.Margin = new Thickness(10,3,0,0);
switch (tipoAtributo)
{
case "Boolean":
CheckBox campoBooleano = new CheckBox();
campoBooleano.Name = atributo.Key;
campoBooleano.IsChecked = ObtenerValorCampoBooleano(atributo.Value);
campoDatos = campoBooleano;
break;
case "DateTime":
DatePicker campoFecha = new DatePicker();
try
{
campoFecha.DisplayDate = DateTime.Parse(atributo.Value);
}
catch (Exception)
{
campoFecha.DisplayDate = DateTime.Now;
}
campoDatos = campoFecha;
break;
default:
TextBox campoTexto = new TextBox();
campoTexto.Text = atributo.Value == null ? "" : atributo.Value;
campoDatos = campoTexto;
break;
}
campoDatos.Margin = new Thickness(0,1,10,1);
rootPage.NuevoElementoWindowInstance.NuevoElementoInstance.ListadoAtributos.RowDefinitions.Add(new RowDefinition());
Grid.SetColumn(campoDatos, 1);
Grid.SetColumn(bloqueTexto, 0);
Grid.SetRow(campoDatos, numeroFila);
Grid.SetRow(bloqueTexto, numeroFila);
rootPage.NuevoElementoWindowInstance.NuevoElementoInstance.ListadoAtributos.Children.Add(bloqueTexto);
rootPage.NuevoElementoWindowInstance.NuevoElementoInstance.ListadoAtributos.Children.Add(campoDatos);
numeroFila++;
}
}

I have found the solution. This is the code:
int numeroFila = 0;
MainPage rootPage = ((App)Application.Current).RootVisual as MainPage;
rootPage.NuevoElementoWindowInstance.NuevoElementoInstance.ListadoAtributos.Children.Clear();
foreach (var atributo in ListaAtributos)
{
string tipoAtributo = ObtenerDefinicionAtributo(atributo.Key);
FrameworkElement campoDatos;
TextBlock bloqueTexto = new TextBlock();
bloqueTexto.Margin = new Thickness(10,3,0,0);
Binding bind = new Binding();
bind.Source = atributo;
bind.Path = new PropertyPath("Key");
bind.Mode = System.Windows.Data.BindingMode.TwoWay;
bloqueTexto.SetBinding(TextBlock.TextProperty, bind);
switch (tipoAtributo)
{
case "Boolean":
CheckBox campoBooleano = new CheckBox();
campoBooleano.Name = atributo.Key;
campoBooleano.IsChecked = ObtenerValorCampoBooleano(atributo.Value);
bind = new Binding();
bind.Source = atributo;
bind.Path = new PropertyPath("Value");
bind.Mode = System.Windows.Data.BindingMode.TwoWay;
campoBooleano.SetBinding(CheckBox.IsCheckedProperty, bind);
campoDatos = campoBooleano;
break;
case "DateTime":
DatePicker campoFecha = new DatePicker();
try
{
campoFecha.DisplayDate = DateTime.Parse(atributo.Value);
}
catch (Exception)
{
campoFecha.DisplayDate = DateTime.Now;
}
bind = new Binding();
bind.Source = atributo;
bind.Path = new PropertyPath("Value");
bind.Mode = System.Windows.Data.BindingMode.TwoWay;
campoFecha.SetBinding(DatePicker.TextProperty, bind);
campoDatos = campoFecha;
break;
default:
TextBox campoTexto = new TextBox();
atributo.Value = atributo.Value == null ? "" : atributo.Value;
bind = new Binding();
bind.Source = atributo;
bind.Path = new PropertyPath("Value");
bind.Mode = System.Windows.Data.BindingMode.TwoWay;
campoTexto.SetBinding(TextBox.TextProperty, bind);
campoDatos = campoTexto;
break;
}
//this.GetType().GetProperty("").GetGetMethod().Invoke(new Object(), null);
campoDatos.Margin = new Thickness(0,1,10,1);
rootPage.NuevoElementoWindowInstance.NuevoElementoInstance.ListadoAtributos.RowDefinitions.Add(new RowDefinition());
Grid.SetColumn(campoDatos, 1);
Grid.SetColumn(bloqueTexto, 0);
Grid.SetRow(campoDatos, numeroFila);
Grid.SetRow(bloqueTexto, numeroFila);
rootPage.NuevoElementoWindowInstance.NuevoElementoInstance.ListadoAtributos.Children.Add(bloqueTexto);
rootPage.NuevoElementoWindowInstance.NuevoElementoInstance.ListadoAtributos.Children.Add(campoDatos);
numeroFila++;
}
However now, I need to set a Converter to the CheckBox, because al "Values" are string and I need to convert string-boolean

Related

How to make a listview work in Xamarin (VS 2022)

Here's this code. It sort of runs but then abends. How do I make the choice work? And additionally, I wrote (copied) this code about 18 months ago, so I am vague as to why it seems so backward:
void SwitchNumber()
{
var dialogView = LayoutInflater.Inflate(Resource.Layout.list_view, null);
Android.App.AlertDialog alertDialog;
listview = dialogView.FindViewById<ListView>(Resource.Id.listview);
textview = dialogView.FindViewById<TextView>(Resource.Id.textview);
var items = new string[] { "1","2","3" };
var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);
using (var dialog = new Android.App.AlertDialog.Builder(this))
{
listview.Adapter = adapter;
listview.ItemClick += Listview_ItemClick;
dialog.SetTitle("Switch Number");
dialog.SetMessage("Click on the number you want to switch to");
dialog.SetView(dialogView);
string newNumber = string.Empty;
dialog.SetNegativeButton("Cancel", (s, a) => { });
dialog.SetPositiveButton("OK", (s, a) =>
{
switch (prefs.GetInt("selectitemforAlert", 0))
{
case 0:
newNumber = "1";
break;
case 1:
newNumber = "2";
break;
case 2:
newNumber = "3";
break;
default:
currentNumber = "1";
break;
}
}//switch
);
if (newNumber == currentNumber) return;
ChangeNumber(newNumber);
alertDialog = dialog.Create();
// }
}
//using
dialogView.FindViewById<ListView>(Resource.Id.listview).Adapter = adapter;
alertDialog.Show();
listview.Adapter = adapter;
listview.ItemClick += Listview_ItemClick;
}
The list does appear but I get a null object reference.

how to validate that a name entered using mvc doesn't exist in database

i am using sql server which is case sensitive. How can i convert the data so that it may be validated without being case sensitive
CODE:-
using (var kk = new TeamRepository(context))
{
var data = new Team();
var find = kk.GetAll().ToString();
if (find.Any(x => x.TeamName == apview.TeamName))
{
return false;
}
else
{
var _pointrepo = new PointsRepositotry(context);
if (image != null)
{
apview.ImageMimeType = image.ContentType;
apview.TeamLogo = new byte[image.ContentLength];
image.InputStream.Read(apview.TeamLogo, 0, image.ContentLength);
}
data.TeamLogo = apview.TeamLogo;
data.TeamName = apview.TeamName;
data.TeamEmail = apview.TeamEmail;
data.Contact_Number = apview.ContactNumber;
data.TeamNickName = apview.TeamNickName;
data.YearEstablished = apview.YearEstablished;
var points = new Points();
points.TeamName = apview.TeamName;
data.ImageMimeType = apview.ImageMimeType;
return kk.Insert(data);
//_pointrepo.Insert(points);
}
you can use ToLower
find.Any(x => x.TeamName.ToLower() == apview.TeamName.ToLower())
https://msdn.microsoft.com/en-us/library/e78f86at%28v=vs.110%29.aspx

Change colors in devexpress charts

I am drawing a pie chart using Devexpress in my MVC project.
While doing it by default my chart generated with three colors, as below
but my client is not satisfied, with the colors of it and wanted me to change them which match with our application background, so please help me, how to do this.
Thanks in advance.
Here is my code.
settings.Name = "chart";
settings.Width = 600;
settings.Height = 250;
settings.BorderOptions.Visible = false;
Series series1 = new Series("Type", DevExpress.XtraCharts.ViewType.Pie3D);
settings.Series.Add(series1);
series1.ArgumentScaleType = ScaleType.Qualitative;
series1.ArgumentDataMember = "ClassName";
series1.ValueScaleType = ScaleType.Numerical;
series1.ValueDataMembers.AddRange(new string[] { "PercentageValues" });
series1.LegendPointOptions.PointView = PointView.ArgumentAndValues;
series1.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
series1.LegendPointOptions.ValueNumericOptions.Precision = 0;
series1.Label.ResolveOverlappingMode = ResolveOverlappingMode.Default;
series1.Label.Visible = false;
Please refer the following code. I have successfully implemented the same for giving custom color for rangebar. I guess it will work for your case also
settings.CustomDrawSeriesPoint = (s, ev) =>
{
BarDrawOptions drawOptions = ev.SeriesDrawOptions as BarDrawOptions;
if (drawOptions == null)
return;
Color colorInTarget = Color.Blue;
double x = ev.SeriesPoint.Values[0];
double y = ev.SeriesPoint.Values[1];
if (x == 0)
{ //Do starting
colorInTarget = Color.FromArgb(159,125, 189);
}
else{
//Red - price Increase
// Green price Decrease
if (y > previousYValue)
{
colorInTarget = Color.Red; ;
}
else
{
colorInTarget = Color.Green;
}
}
previousYValue = y;
drawOptions.Color = colorInTarget;
drawOptions.FillStyle.FillMode = FillMode.Solid;
drawOptions.Border.Color = Color.Transparent;
};
you can set the theme and palette properties of the chart control. follow the links below to devexpress documentation. although the examples refers to winform application they are still avaliable in asp.net mvc controls.
http://documentation.devexpress.com/#WindowsForms/CustomDocument7433
http://documentation.devexpress.com/#WindowsForms/CustomDocument5538
// Define the chart's appearance and palette.
barChart.AppearanceName = "Dark";
barChart.PaletteName = "Opulent";
private List<StudentClass.ChartsPointsSummary> GetStudentSummaryResults()
{
var StudentId = Convert.ToInt32(Request.Params["StudentID"]);
var StudentDetailsP = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
var Presents = StudentDetailsP.Select(p => new { p.Months, p.Presents});
var CountsP = StudentDetailsP.Count();
List<StudentClass.ChartsPointsSummary> MT = new List<StudentClass.ChartsPointsSummary>();
foreach (var ab in Presents)
{
MT.Add(new StudentClass.ChartsPointsSummary { PresentSummaryX = ab.Months, PresentSummaryY = Convert.ToInt32(ab.Presents) });
}
var StudentDetailsA = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
var Absents = StudentDetailsP.Select(p => new { p.Months, p.Absents });
var CountsA = StudentDetailsA.Count();
foreach (var ab in Absents)
{
MT.Add(new StudentClass.ChartsPointsSummary { AbsentSummaryX = ab.Months, AbsentSummaryY = Convert.ToInt32(ab.Absents) });
}
var StudentDetailsL = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
var CountL = StudentDetailsL.Count();
var Leaves = StudentDetailsP.Select(p => new { p.Months, p.Leaves });
foreach (var ab in Leaves)
{
MT.Add(new StudentClass.ChartsPointsSummary { LeaveSummaryX = ab.Months, LeaveSummaryY = Convert.ToInt32(ab.Leaves) });
}
return MT;
}
#Html.DevExpress().Chart(settings =>
{
settings.Name = "SummaryDetailsById";
settings.Width = 1032;
settings.Height = 250;
Series chartSeries = new Series("Presents", DevExpress.XtraCharts.ViewType.Bar);
chartSeries.ArgumentDataMember = "PresentSummaryX";
chartSeries.ValueDataMembers[0] = "PresentSummaryY";
settings.Series.Add(chartSeries);
Series chartSeries2 = new Series("Absents", DevExpress.XtraCharts.ViewType.Bar);
chartSeries2.ArgumentDataMember = "AbsentSummaryX";
chartSeries2.ValueDataMembers[0] = "AbsentSummaryY";
settings.Series.Add(chartSeries2);
Series chartSeries3 = new Series("Leaves", DevExpress.XtraCharts.ViewType.Bar);
chartSeries3.ArgumentDataMember = "LeaveSummaryX";
chartSeries3.ValueDataMembers[0] = "LeaveSummaryY";
settings.Series.Add(chartSeries3);
settings.CrosshairEnabled = DefaultBoolean.Default;
settings.BackColor = System.Drawing.Color.Transparent;
settings.BorderOptions.Visibility = DefaultBoolean.True;
settings.Titles.Add(new ChartTitle()
{
Text = "Student Attendance Summary"
});
XYDiagram diagram = ((XYDiagram)settings.Diagram);
diagram.AxisX.Label.Angle = -30;
diagram.AxisY.Interlaced = true;
}).Bind(Model).GetHtml()

How to write ItemQuery using ListIdSet?

I have requirement to retrive Item information for multiple Ids, I am using ItemQuery for the same using below code,but its gives error as "{"Invalid or missing value of the choice identifier 'ItemsElementName' of type 'Intuit.Ipp.Data.Qbd.ItemsChoiceType4[]'."}".
Please suggest if anyone is having any idea about how to use ListIdSet for ItemQuery .
List<Intuit.Ipp.Data.Qbd.IdType> ids = new List<Intuit.Ipp.Data.Qbd.IdType>();
ids.Add(new Intuit.Ipp.Data.Qbd.IdType() { Value = "123460", idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.NG });
ids.Add(new Intuit.Ipp.Data.Qbd.IdType() { Value = "789100", idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.NG });
ids.Add(new Intuit.Ipp.Data.Qbd.IdType() { Value = "111213", idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.NG });
Intuit.Ipp.Data.Qbd.ItemQuery qbdQuery = new Intuit.Ipp.Data.Qbd.ItemQuery();
List<Intuit.Ipp.Data.Qbd.Item> itemQueryResult = null;
qbdQuery.Items = ids.ToArray();
qbdQuery.ItemsElementName = new ItemsChoiceType4[] { ItemsChoiceType4.ListIdSet};
itemQueryResult = qbdQuery.ExecuteQuery<Intuit.Ipp.Data.Qbd.Item>(context).ToList<Intuit.Ipp.Data.Qbd.Item>();
Regards,
Reshma D.
Here is an example
ItemQuery qbdItemQuery = new ItemQuery();
qbdItemQuery.Items = new object[] { new IdSet() { Id = new IdType[] { new IdType() { idDomain = idDomainEnum.NG, Value = "79841" } } } };
qbdItemQuery.ItemsElementName = new ItemsChoiceType4[] { ItemsChoiceType4.ListIdSet };
List<Item> ItemQueryResult = qbdItemQuery.ExecuteQuery<Item>(context).ToList<Item>();

Open XML SDK - image not showing in excel

I'm able to successfully create a spreadsheet, and I appear to have added the image via code, the problem is that when I open the spreadsheet, there is no image. Here is my code:
public static void CreateSpreadsheetWorkbook(string filepath)
{
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);
WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());
Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
sheets.Append(sheet);
string sImagePath = #"C:\temp\install_button.png";
DrawingsPart drawingsPart = worksheetPart.AddNewPart<DrawingsPart>();
ImagePart imagePart = drawingsPart.AddImagePart(ImagePartType.Png, worksheetPart.GetIdOfPart(drawingsPart));
using (FileStream stream = new FileStream(sImagePath, FileMode.Open))
{
imagePart.FeedData(stream);
}
workbookpart.Workbook.Save();
spreadsheetDocument.Close();
}
Thanks
Stu
Normally when I can't figure out why something doesn't work when dealing with the Open XML SDK I use the Open XML SDK 2.0 Productivity Tool to figure out what the code should be. I will normally create a blank worksheet in Excel, add a picture and then save the document. Then I will open that document in the Productivity tool and click the Reflect code button to see how to recreate that document. I did that to see how to answer your question and got the following code to create a worksheet part:
// Adds child parts and generates content of the specified part.
public void CreateWorksheetPart(WorksheetPart part)
{
DrawingsPart drawingsPart1 = part.AddNewPart<DrawingsPart>("rId2");
GenerateDrawingsPart1Content(drawingsPart1);
ImagePart imagePart1 = drawingsPart1.AddNewPart<ImagePart>("image/png", "rId1");
GenerateImagePart1Content(imagePart1);
SpreadsheetPrinterSettingsPart spreadsheetPrinterSettingsPart1 = part.AddNewPart<SpreadsheetPrinterSettingsPart>("rId1");
GenerateSpreadsheetPrinterSettingsPart1Content(spreadsheetPrinterSettingsPart1);
GeneratePartContent(part);
}
// Generates content of drawingsPart1.
private void GenerateDrawingsPart1Content(DrawingsPart drawingsPart1)
{
Xdr.WorksheetDrawing worksheetDrawing1 = new Xdr.WorksheetDrawing();
worksheetDrawing1.AddNamespaceDeclaration("xdr", "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing");
worksheetDrawing1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
Xdr.TwoCellAnchor twoCellAnchor1 = new Xdr.TwoCellAnchor(){ EditAs = Xdr.EditAsValues.OneCell };
Xdr.FromMarker fromMarker1 = new Xdr.FromMarker();
Xdr.ColumnId columnId1 = new Xdr.ColumnId();
columnId1.Text = "0";
Xdr.ColumnOffset columnOffset1 = new Xdr.ColumnOffset();
columnOffset1.Text = "0";
Xdr.RowId rowId1 = new Xdr.RowId();
rowId1.Text = "0";
Xdr.RowOffset rowOffset1 = new Xdr.RowOffset();
rowOffset1.Text = "0";
fromMarker1.Append(columnId1);
fromMarker1.Append(columnOffset1);
fromMarker1.Append(rowId1);
fromMarker1.Append(rowOffset1);
Xdr.ToMarker toMarker1 = new Xdr.ToMarker();
Xdr.ColumnId columnId2 = new Xdr.ColumnId();
columnId2.Text = "0";
Xdr.ColumnOffset columnOffset2 = new Xdr.ColumnOffset();
columnOffset2.Text = "171429";
Xdr.RowId rowId2 = new Xdr.RowId();
rowId2.Text = "0";
Xdr.RowOffset rowOffset2 = new Xdr.RowOffset();
rowOffset2.Text = "171429";
toMarker1.Append(columnId2);
toMarker1.Append(columnOffset2);
toMarker1.Append(rowId2);
toMarker1.Append(rowOffset2);
Xdr.Picture picture1 = new Xdr.Picture();
Xdr.NonVisualPictureProperties nonVisualPictureProperties1 = new Xdr.NonVisualPictureProperties();
Xdr.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Xdr.NonVisualDrawingProperties(){ Id = (UInt32Value)2U, Name = "Picture 1", Description = "eprs_reports_arrow.png" };
Xdr.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 = new Xdr.NonVisualPictureDrawingProperties();
A.PictureLocks pictureLocks1 = new A.PictureLocks(){ NoChangeAspect = true };
nonVisualPictureDrawingProperties1.Append(pictureLocks1);
nonVisualPictureProperties1.Append(nonVisualDrawingProperties1);
nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);
Xdr.BlipFill blipFill1 = new Xdr.BlipFill();
A.Blip blip1 = new A.Blip(){ Embed = "rId1", CompressionState = A.BlipCompressionValues.Print };
blip1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
A.Stretch stretch1 = new A.Stretch();
A.FillRectangle fillRectangle1 = new A.FillRectangle();
stretch1.Append(fillRectangle1);
blipFill1.Append(blip1);
blipFill1.Append(stretch1);
Xdr.ShapeProperties shapeProperties1 = new Xdr.ShapeProperties();
A.Transform2D transform2D1 = new A.Transform2D();
A.Offset offset1 = new A.Offset(){ X = 0L, Y = 0L };
A.Extents extents1 = new A.Extents(){ Cx = 171429L, Cy = 171429L };
transform2D1.Append(offset1);
transform2D1.Append(extents1);
A.PresetGeometry presetGeometry1 = new A.PresetGeometry(){ Preset = A.ShapeTypeValues.Rectangle };
A.AdjustValueList adjustValueList1 = new A.AdjustValueList();
presetGeometry1.Append(adjustValueList1);
shapeProperties1.Append(transform2D1);
shapeProperties1.Append(presetGeometry1);
picture1.Append(nonVisualPictureProperties1);
picture1.Append(blipFill1);
picture1.Append(shapeProperties1);
Xdr.ClientData clientData1 = new Xdr.ClientData();
twoCellAnchor1.Append(fromMarker1);
twoCellAnchor1.Append(toMarker1);
twoCellAnchor1.Append(picture1);
twoCellAnchor1.Append(clientData1);
worksheetDrawing1.Append(twoCellAnchor1);
drawingsPart1.WorksheetDrawing = worksheetDrawing1;
}
// Generates content of imagePart1.
private void GenerateImagePart1Content(ImagePart imagePart1)
{
System.IO.Stream data = GetBinaryDataStream(imagePart1Data);
imagePart1.FeedData(data);
data.Close();
}
// Generates content of spreadsheetPrinterSettingsPart1.
private void GenerateSpreadsheetPrinterSettingsPart1Content(SpreadsheetPrinterSettingsPart spreadsheetPrinterSettingsPart1)
{
System.IO.Stream data = GetBinaryDataStream(spreadsheetPrinterSettingsPart1Data);
spreadsheetPrinterSettingsPart1.FeedData(data);
data.Close();
}
// Generates content of part.
private void GeneratePartContent(WorksheetPart part)
{
Worksheet worksheet1 = new Worksheet();
worksheet1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
SheetDimension sheetDimension1 = new SheetDimension(){ Reference = "A1" };
SheetViews sheetViews1 = new SheetViews();
SheetView sheetView1 = new SheetView(){ TabSelected = true, WorkbookViewId = (UInt32Value)0U };
sheetViews1.Append(sheetView1);
SheetFormatProperties sheetFormatProperties1 = new SheetFormatProperties(){ DefaultRowHeight = 15D };
SheetData sheetData1 = new SheetData();
PageMargins pageMargins1 = new PageMargins(){ Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
PageSetup pageSetup1 = new PageSetup(){ Orientation = OrientationValues.Portrait, Id = "rId1" };
Drawing drawing1 = new Drawing(){ Id = "rId2" };
worksheet1.Append(sheetDimension1);
worksheet1.Append(sheetViews1);
worksheet1.Append(sheetFormatProperties1);
worksheet1.Append(sheetData1);
worksheet1.Append(pageMargins1);
worksheet1.Append(pageSetup1);
worksheet1.Append(drawing1);
part.Worksheet = worksheet1;
}
#region Binary Data
private string imagePart1Data ="lots of binary data here";
private System.IO.Stream GetBinaryDataStream(string base64String)
{
return new System.IO.MemoryStream(System.Convert.FromBase64String(base64String));
}
#endregion
I recommend you do the same with your image and play around with the generated code in order to get it to work since as you can see just adding one picture to a new slide is a lot of code.

Resources