I'm trying to convert every slide of pptx into an image through poi. For example, a text box with bullets in it is a user-defined image. The picture data was lost during conversion。
source file:
image:
public static void saveImg(int width, int height, XSLFSlide slide) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = image.createGraphics();
graphics2D.setPaint(Color.white);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
slide.draw(graphics2D);
String filename = "1.png";
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\Administrator.DESKTOP-L8G4GEP\\Desktop\\ppt-pic\\" + filename)) {
ImageIO.write(image, "png", outputStream);
fileOutputStream.write(outputStream.toByteArray());
fileOutputStream.flush();
graphics2D.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
I would to download a PDF file from iframe it worked in Google chrome and firefox but it not worked in Internet explorer.
This is my code
public void downloadSubscriptionDocument(SessionObject object) {
Document dt = getBlobCode(object);
if (dt != null && dt.getData() != null) {
final FacesContext fContext = FacesContext.getCurrentInstance();
ExternalContext eContext = null;
if (fContext != null && dt != null) {
eContext = fContext.getExternalContext();
if (eContext != null) {
final HttpServletResponse response = (HttpServletResponse) eContext.getResponse();
response.setContentType("application/pdf");
response.addHeader("content-disposition", "attachment; filename=" + "BulletinAdhesion" + ".pdf");
if (dt != null && dt.getData() != null) {
response.addHeader("Content-Length", String.valueOf(dt.getData().length));
}
try {
final ServletOutputStream sos = response.getOutputStream();
sos.write(dt.getData());
sos.flush();
sos.close();
fContext.responseComplete();
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getMessage());
}
}
}
}
else {
Locale locale = new Locale("fr");
this.addMessageError(ResourceBundle.getBundle("messages", locale).getString("eu.spb.afflelou.pdv.ba.not.found"));
return ;
}
}
I have this exception in console
Servlet] - 2019-12-04 10:30:29,289 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/spb-extranet-afflelou-pdv].[Faces Servlet]] (ajp-/10.7.2.55 {s2jbossrecex.spb.eu} :8809-3) JBWEB000236: Servlet.service() for servlet Faces Servlet threw exception: java.lang.IllegalStateException: JBWEB000028: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:621) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:191) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:778) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at javax.faces.context.ExternalContextWrapper.getResponseOutputWriter(ExternalContextWrapper.java:669) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1110) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.event(JBossWebContext.java:91)
at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.invoke(JBossWebContext.java:72)
at org.jboss.as.web.security.SubjectInfoSetupValve.invoke(SubjectInfoSetupValve.java:34) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.session.ClusteredSessionValve.handleRequest(ClusteredSessionValve.java:134) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:99) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.session.JvmRouteValve.invoke(JvmRouteValve.java:95) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.session.LockingValve.invoke(LockingValve.java:64) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:490) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:422) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
My code right now for didSelectItemAtIndexPath is the following:
- (void)collectionView:(AFIndexedCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
if(collectionView.index == 0){
NSLog(#"Reordenador contenido por columna %li",indexPath.item);
self.my_data = [self.my_data sortByColumn:indexPath.item skip:1 areAllNumbers:TRUE];
[self.tableView reloadData];
}else{
//show a new window with the content of the cell in a Text Field
NSLog(#"Row = %li; Column = %li - content = %#",collectionView.index,indexPath.item,[self.my_data objectInRow:collectionView.index column:indexPath.item]);
}
}
my_data = custom 2D array class object
How would I programmatically open a new popup window / new view with the content of the selected cell inside, for example, a Text Field, and 2 buttons - Save / Cancel?
Fixed with the following coding:
UIView *mySubView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
[mySubView setBackgroundColor:[UIColor blackColor]];
mySubView.tag = TFIELDSUBVIEW_TAG;
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(2, 10, 300, 80)];
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.font = [UIFont systemFontOfSize:12];
self.textField.placeholder = [self.the_matrix objectInRow:collectionView.index column:indexPath.item];
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.keyboardType = UIKeyboardTypeDefault;
self.textField.returnKeyType = UIReturnKeyDone;
self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.textField.textAlignment = NSTextAlignmentCenter;
self.textFieldColumn = indexPath.item;
self.textFieldRow = collectionView.index;
UIButton *buttonOK = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonOK.tag = TFIELDSUBVIEW_TAG;
[buttonOK setBackgroundImage:[UIImage imageNamed:#"ok.jpg"] forState:UIControlStateNormal];
[buttonOK addTarget:self
action:#selector(okClicked)
forControlEvents:UIControlEventTouchUpInside];
[buttonOK setTitle:#"" forState:UIControlStateNormal];
buttonOK.backgroundColor = [UIColor grayColor];
buttonOK.frame = CGRectMake(50, 100, 50, 30);
buttonOK.tintColor = [UIColor greenColor];
UIButton *buttonCANCEL = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonCANCEL.tag = TFIELDSUBVIEW_TAG;
[buttonCANCEL addTarget:self
action:#selector(cancelClicked)
forControlEvents:UIControlEventTouchUpInside];
[buttonCANCEL setBackgroundImage:[UIImage imageNamed:#"cancel.jpg"] forState:UIControlStateNormal];
[buttonCANCEL setTitle:#"" forState:UIControlStateNormal];
buttonCANCEL.backgroundColor = [UIColor grayColor];
buttonCANCEL.frame = CGRectMake(120, 100, 75, 30);
buttonCANCEL.tintColor = [UIColor redColor];
[mySubView addSubview:buttonOK];
[mySubView addSubview:buttonCANCEL];
[mySubView addSubview:self.textField];
[self setCustomView:mySubView];
[self.view reloadInputViews];
setCustomView being the following:
-(void) setCustomView:(UIView *)customView {
NSUInteger z = NSNotFound;
if (_customView) {
z = [self.view.subviews indexOfObject:_customView];
}
if (z == NSNotFound) {
[self.view addSubview:customView];
} else {
UIView *superview = _customView.superview;
[_customView removeFromSuperview];
[superview insertSubview:customView atIndex:z];
}
_customView = customView;
}
if I use
-(void)viewWillDisappear:(BOOL)animated
{
[subView loadHTMLString:nil baseURL:nil];
}
my Webview can't worked
I try to do this
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
[subView loadHTMLString:nil baseURL:nil];
}
I just want to go next page with paging scrollview and stop video on next page
this my code scrollview paging
book = [[NSMutableArray alloc] initWithObjects:#"page11",#"page12",#"page13",#"page14",#"page15", nil];
for (int i = 0; i < [book count]; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.height * i;
frame.origin.y = 0;
frame.size = CGSizeMake(1024,768);
subView = [[UIWebView alloc] initWithFrame:frame];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:i] ofType:#"html" inDirectory:#""]];
[subView loadRequest:[NSURLRequest requestWithURL:url]];
subView.scalesPageToFit = YES;
[scrollView setBounces:NO];
[scrollView addSubview:subView];
}
scrollView.contentSize = CGSizeMake(1024 * [book count], 768);
[scrollView setFrame:CGRectMake(0, 0, 1024, 768)];
Can I play video and stop on I next page? //Please advice
sorry my English isn't well
You need to load a blank page into the UIWebView to stop the audio:
[self.webView loadRequest:NSURLRequestFromString(#"about:blank")];
or
[self.webView loadHTMLString:#"" baseURL:nil];
Thank for Advice. I try this is works for me
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
for(int i = 0; i < _pageAmount ; i++){
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
[_collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor clearColor];
}
currentPage = page;
if (currentPage > 0 && currentPage < [book count]-1) {
[[self.scrollView.subviews objectAtIndex:currentPage-1]reload];//
[[self.scrollView.subviews objectAtIndex:currentPage+1]reload];
}
if(self.interfaceOrientation == 1 || self.interfaceOrientation == 2){
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:page inSection:0];
[_collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor redColor];
}
}
I need to export multiple data tables to Excel on the clients machine, each to their own sheet. If it was just one sheet, I'd use the Excel/csv content type, but I've heard something about an XML format that can represent an entire workbook. I don't want to go down the Packaging and .xlsx route, so I need standard .xls.
Our bug tracker, Gemini, used to have an export function that produced an XML file that Excel automatically opened as a multi-sheet workbook, but I can't find it. Is there still such a mechanism, and where can I find that schema?
You can use for example this library, if you don't want to create your own Excel XML writer library.
In Excel you can save a workbook in XML format. (in Excel 2007 it is called XML Spreadsheet 2003).
That might get you started.
USE The Below In seperate class file and on page.cs file paste the the function like this on button click:
ExcelHelperNS.ExcelHelper.ToExcel(Dataset1, "ExcelFileName", Page.Response);
use this in separate class and it will work..
public class ExcelHelper
{
//Row limits older excel verion per sheet, the row limit for excel 2003 is 65536
const int rowLimit = 65000;
private static string getWorkbookTemplate()
{
var sb = new StringBuilder(818);
sb.AppendFormat(#"<?xml version=""1.0""?>{0}", Environment.NewLine);
sb.AppendFormat(#"<?mso-application progid=""Excel.Sheet""?>{0}", Environment.NewLine);
sb.AppendFormat(#"<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine);
sb.AppendFormat(#" xmlns:o=""urn:schemas-microsoft-com:office:office""{0}", Environment.NewLine);
sb.AppendFormat(#" xmlns:x=""urn:schemas-microsoft-com:office:excel""{0}", Environment.NewLine);
sb.AppendFormat(#" xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine);
sb.AppendFormat(#" xmlns:html=""http://www.w3.org/TR/REC-html40"">{0}", Environment.NewLine);
sb.AppendFormat(#" <Styles>{0}", Environment.NewLine);
sb.AppendFormat(#" <Style ss:ID=""Default"" ss:Name=""Normal"">{0}", Environment.NewLine);
sb.AppendFormat(#" <Alignment ss:Vertical=""Bottom""/>{0}", Environment.NewLine);
sb.AppendFormat(#" <Borders/>{0}", Environment.NewLine);
sb.AppendFormat(#" <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000""/>{0}", Environment.NewLine);
sb.AppendFormat(#" <Interior/>{0}", Environment.NewLine);
sb.AppendFormat(#" <NumberFormat/>{0}", Environment.NewLine);
sb.AppendFormat(#" <Protection/>{0}", Environment.NewLine);
sb.AppendFormat(#" </Style>{0}", Environment.NewLine);
sb.AppendFormat(#" <Style ss:ID=""s62"">{0}", Environment.NewLine);
sb.AppendFormat(#" <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000""{0}", Environment.NewLine);
sb.AppendFormat(#" ss:Bold=""1""/>{0}", Environment.NewLine);
sb.AppendFormat(#" </Style>{0}", Environment.NewLine);
sb.AppendFormat(#" <Style ss:ID=""s63"">{0}", Environment.NewLine);
sb.AppendFormat(#" <NumberFormat ss:Format=""Short Date""/>{0}", Environment.NewLine);
sb.AppendFormat(#" </Style>{0}", Environment.NewLine);
sb.AppendFormat(#" </Styles>{0}", Environment.NewLine);
sb.Append(#"{0}\r\n</Workbook>");
return sb.ToString();
}
private static string replaceXmlChar(string input)
{
input = input.Replace("&", "&");
input = input.Replace("<", "<");
input = input.Replace(">", ">");
input = input.Replace("\"", """);
input = input.Replace("'", "'");
return input;
}
private static string getCell(Type type, object cellData)
{
var data = (cellData is DBNull) ? "" : cellData;
if (type.Name.Contains("Int") || type.Name.Contains("Double") || type.Name.Contains("Decimal")) return string.Format("<Cell><Data ss:Type=\"Number\">{0}</Data></Cell>", data);
if (type.Name.Contains("Date") && data.ToString() != string.Empty)
{
return string.Format("<Cell ss:StyleID=\"s63\"><Data ss:Type=\"DateTime\">{0}</Data></Cell>", Convert.ToDateTime(data).ToString("yyyy-MM-dd"));
}
return string.Format("<Cell><Data ss:Type=\"String\">{0}</Data></Cell>", replaceXmlChar(data.ToString()));
}
private static string getWorksheets(DataSet source)
{
var sw = new StringWriter();
if (source == null || source.Tables.Count == 0)
{
sw.Write("<Worksheet ss:Name=\"Sheet1\">\r\n<Table>\r\n<Row><Cell><Data ss:Type=\"String\"></Data></Cell></Row>\r\n</Table>\r\n</Worksheet>");
return sw.ToString();
}
foreach (DataTable dt in source.Tables)
{
if (dt.Rows.Count == 0)
sw.Write("<Worksheet ss:Name=\"" + replaceXmlChar(dt.TableName) + "\">\r\n<Table>\r\n<Row><Cell ss:StyleID=\"s62\"><Data ss:Type=\"String\"></Data></Cell></Row>\r\n</Table>\r\n</Worksheet>");
else
{
//write each row data
var sheetCount = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
if ((i % rowLimit) == 0)
{
//add close tags for previous sheet of the same data table
if ((i / rowLimit) > sheetCount)
{
sw.Write("\r\n</Table>\r\n</Worksheet>");
sheetCount = (i / rowLimit);
}
sw.Write("\r\n<Worksheet ss:Name=\"" + replaceXmlChar(dt.TableName) +
(((i / rowLimit) == 0) ? "" : Convert.ToString(i / rowLimit)) + "\">\r\n<Table>");
//write column name row
sw.Write("\r\n<Row>");
foreach (DataColumn dc in dt.Columns)
sw.Write(string.Format("<Cell ss:StyleID=\"s62\"><Data ss:Type=\"String\">{0}</Data></Cell>", replaceXmlChar(dc.ColumnName)));
sw.Write("</Row>");
}
sw.Write("\r\n<Row>");
foreach (DataColumn dc in dt.Columns)
sw.Write(getCell(dc.DataType, dt.Rows[i][dc.ColumnName]));
sw.Write("</Row>");
}
sw.Write("\r\n</Table>\r\n</Worksheet>");
}
}
return sw.ToString();
}
public static string GetExcelXml(DataTable dtInput, string filename)
{
var excelTemplate = getWorkbookTemplate();
var ds = new DataSet();
ds.Tables.Add(dtInput.Copy());
var worksheets = getWorksheets(ds);
var excelXml = string.Format(excelTemplate, worksheets);
return excelXml;
}
public static string GetExcelXml(DataSet dsInput, string filename)
{
var excelTemplate = getWorkbookTemplate();
var worksheets = getWorksheets(dsInput);
var excelXml = string.Format(excelTemplate, worksheets);
return excelXml;
}
public static void ToExcel(DataSet dsInput, string filename, HttpResponse response)
{
var excelXml = GetExcelXml(dsInput, filename);
response.Clear();
response.AppendHeader("Content-Type", "application/vnd.ms-excel");
response.AppendHeader("Content-disposition", "attachment; filename=" + filename);
response.Write(excelXml);
response.Flush();
response.End();
}
public static void ToExcel(DataTable dtInput, string filename, HttpResponse response)
{
var ds = new DataSet();
ds.Tables.Add(dtInput.Copy());
ToExcel(ds, filename, response);
}
}